View Full Version : Does Script still run
06-15-2010, 04:42 PM
Say i have a php cron script that runs for 10 mins. If i run that script from a web browser and then close the browser down halfway through the script completing. Would the script continue to run in the background? Or does the script stop when i close the browser window down?
06-15-2010, 04:51 PM
It'll stop when the script completes or exits. The browser state is irrelevant once the script is called, unless further user input is required.
06-15-2010, 05:43 PM
I don't think the answer is that straightforward.
06-16-2010, 04:21 PM
Default it will terminate when a user closes their browser, unless ignoring the user abort as tomws posted a link to.
Command line behaviour is different, it should work indefinitely until:
Allocated memory to PHP is exhausted.
Allowed time for PHP is exceeded.
Process is terminated.
In the event that memory allocation is infinite:
All available memory is exhausted
In the event that time allowed is infinite
Script will not terminate by cause of time.
Most terminations from a user are ignored though, but not by PHP/Apache. This is simply because we send request to the server via stateless protocol, and it has no idea if we're still listening, so it simply throws it back to us. If we don't respond, it only tries a couple more times and then gives up (this is the communication though, still not PHP/Apache).
The only way to really see the disconnection behaviour is to run an infinite loop with some flushes. Upon termination by checking for connection status, write output to a file (pretty much the same as the example in the ignore user abort page actually, except we added a file write). I believe this also qualifies if a user hits the stop button on an infinite script.
06-16-2010, 04:54 PM
Thanks that explains a lot.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.