By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

curl twice

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.