473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

curl twice


I'm using curl to invoke a php script on the same site/server. It works
great, but if I call it again while it's still running, nothing happens.

Why? Can that be fixed?

Why use curl? To make it run in the background. My host can't use exec
nor flush the output to the browser. But, I can use curl and timeout.
Nov 15 '06 #1
4 5511
Terry wrote:
>
I'm using curl to invoke a php script on the same site/server. It works
great, but if I call it again while it's still running, nothing happens.

Why? Can that be fixed?

Why use curl? To make it run in the background. My host can't use exec
nor flush the output to the browser. But, I can use curl and timeout.
Hi,

Maybe SESSIONs are involved?
PHP serves only 1 page to a single user untill that one ends (if you use
sessions).
The reason is this:
1) First request uses session, and gets a lock on the sessionstoragefile
2) first scripts keeps running....
3) Second call to some script wants to use the same session.
4) Second call hangs and waits for the first to finish, so it can get a lock
on the sessionfile.

Could this be your scenario? Does you app use sessions?

Regards,
Erwin Moller

Nov 15 '06 #2
In article <45*********************@news.xs4all.nl>,
Erwin Moller
<si******************************************@spam yourself.comwrote:
Maybe SESSIONs are involved?
PHP serves only 1 page to a single user untill that one ends (if you use
sessions).
The reason is this:
1) First request uses session, and gets a lock on the sessionstoragefile
2) first scripts keeps running....
3) Second call to some script wants to use the same session.
4) Second call hangs and waits for the first to finish, so it can get a lock
on the sessionfile.

Could this be your scenario? Does you app use sessions?
Well, I don't think so. I'm not calling session_start(), and according
to phpinfo():
Session support is enabled
session.auto_start is Off

Do I have to disable session support? Is there something else I should
check?

Terry
Nov 15 '06 #3

"Terry" <no****@aol.comwrote in message
news:no**************************@newsclstr02.news .prodigy.com...
>
I'm using curl to invoke a php script on the same site/server. It works
great, but if I call it again while it's still running, nothing happens.

Why? Can that be fixed?

Why use curl? To make it run in the background. My host can't use exec
nor flush the output to the browser. But, I can use curl and timeout.
Sorry to hijack the thread, but I'm curious about your use of curl.

Recently, I've been vaguely trying to find a nice, portable way of running
background scripts on the web server (hopefully without any special server
set-ups or privileges). My efforts were predominantly centred around trying
to execute something along the lines of 'php bg.php' using back-ticks,
exec() and so on using various Unix redirection tricks, or 'start /b' under
Windows.

I've never used curl (I assume we're both talking about
http://curl.haxx.se/), and have only the slightest knowledge of what it's
for and how it works, but (to quote you) 'using curl to invoke a php script
[and] make it run in the background' caught my attention.

I don't suppose you could expand on your use of curl for running PHP scripts
in the background could you (or perhaps tell me that I've misunderstood)?

Thanks in advance for any info.

A.
Nov 16 '06 #4
In article <96******************@newsfe7-gui.ntli.net>,
"Andrew C" <no******@totally.made.upwrote:
"Terry" <no****@aol.comwrote in message
news:no**************************@newsclstr02.news .prodigy.com...

I'm using curl to invoke a php script on the same site/server. It works
great, but if I call it again while it's still running, nothing happens.

Why? Can that be fixed?

Why use curl? To make it run in the background. My host can't use exec
nor flush the output to the browser. But, I can use curl and timeout.

Sorry to hijack the thread, but I'm curious about your use of curl.

Recently, I've been vaguely trying to find a nice, portable way of running
background scripts on the web server (hopefully without any special server
set-ups or privileges). My efforts were predominantly centred around trying
to execute something along the lines of 'php bg.php' using back-ticks,
exec() and so on using various Unix redirection tricks, or 'start /b' under
Windows.

I've never used curl (I assume we're both talking about
http://curl.haxx.se/), and have only the slightest knowledge of what it's
for and how it works, but (to quote you) 'using curl to invoke a php script
[and] make it run in the background' caught my attention.

I don't suppose you could expand on your use of curl for running PHP scripts
in the background could you (or perhaps tell me that I've misunderstood)?

Thanks in advance for any info.
See:

http://php.net/curl
http://php.net/curl_init
http://php.net/curl_exec

There are a few comments on background scripts in:

http://php.net/exec
http://php.net/set_time_limit

Normally I use curl as a replacement for file_get_contents, since my
host disables that too, like this:

function my_file_get_contents($url, $timeout = 10)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}

This invokes the script. If you set the timeout to 1, then your main
script gets control back in 1 second. Then in the called script use:

ignore_user_abort(true);
set_time_limit(0);

Then your script can do whatever processing...

If your host lets you flush (my host compresses the pages and I can't
turn it off, so the page never gets sent to the browser until exit, so I
can't really flush), you can, all-in-one-page, flush the page to the
browser, then call ignore_user_abort() set_time_limit() and then do
whatever processing you want. But there may still be other time limits.

Using cron is another option. But, for me, using cron to call my script
every few minutes for something that I need once a week seems pretty
wasteful.

But, I can't get curl to invoke the same page more than once while it's
running. Why? That's what I want to know.

Is it an Apache issue? Does Apache only let one IP access a page once
(curl is coming from my server, not the user, so it's always the same
IP)??

Terry
Nov 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Haluk Durmus | last post by:
Hello I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php from cvs. php couse an ERROR I did the following steps:
8
by: mrbog | last post by:
1. In order to make an http (or https) request with PHP, I need to recompile php with cURL. 2. In order to install CURL I have to upgrade my openssl rpm, even though I'm runing a version of...
3
by: Chris Fortune | last post by:
# uname -a Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28 17:12:37 MSD 2004 i686 i686 i386 GNU/Linux I recompiled PHP with mcrypt, openssl, and curl phpinfo():...
3
by: Hans | last post by:
Hi everybody, I am desperately trying to log into my account at godaddy.com with PHP and Curl and just cannot make it happen. Has anybody written a script for this purpose? Here is what I...
0
by: nfhm2k | last post by:
I've been trying to find a solution to this for quite some time now... I even took a look at existing scripts... Including this one......
1
by: TheSailor | last post by:
Forgive me - I am a bit new to cURL and passing form elements from one site to the next... If you can help with a HOW TO or by holding my hand a bit with examples - so I can learn - I would be in...
4
by: zorro | last post by:
Hello there, I can't figure out why is it that when i use an array for my postfields it doesn't work : this works curl_setopt($curl, CURLOPT_POSTFIELDS, "clown=bozo" ); this doesn't...
0
by: xerc | last post by:
I am trying to create a generic function I can call to download all files from a single remote FTP directory -- using CURL. I want to multi-thread it, but need to get the single thread functionality...
3
by: rottmanj | last post by:
I am re-writing my rets application in perl, and I have found a few modules that will help me on my way. One of them being WWW::Curl:easy. During my testing, I have tested both system curl and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.