I was wondering about the lifespan of a PHP script when called via Ajax. Assume that there is a long-running (i.e. 30 seconds) PHP script on a server and that page is loaded via Ajax. Before the script completes, the user closes the browser. Does the script continue running to completion, is it terminated, or is this a function of the server itself (I'm running Apache fwiw). Thanks for any help.
+1
A:
The script will continue running. Closing the browser on the client does not notify the server to stop processing the request.
Jacob
2010-06-08 23:25:38
Thanks. That was the answer I was hoping for. I probably should have been more specific in my question about my request. Thanks!
Dave
2010-06-09 00:07:04
-1, because, well, false. A script usually keeps running because it hasn't got a non-connection message/quit, by virtue that the leniency for a 'broken' connection in HTTP is quite long, and as a stateless protocol it can only be detected by trying to send data. Most web-based scripts are done long before the timeout occurs. Heed the other `ignore_user_abort` mention if it is important to keep the script running, but even then the webserver itself might decide to kill it.
Wrikken
2010-06-09 01:12:04
Thanks Wrikken, note I said "will continue running" not "will continue running to completion". It is as you say "script usually keeps running". Cheers
Jacob
2010-06-09 01:23:14
The question was literally "Does the script continue running to completion", you reply "will continue running", and when called on it defend the answer by claiming you did not say "will continue running to completion"? At the least the answer is not the answer to the question, but as someone who doesn't know how it works and actually trusts your answer it becomes misleading. No offense intended, keep up the good work and all, but clearly a 'there's a chance it will complete' was not the answer the OP was looking for.
Wrikken
2010-06-09 01:37:44
A:
If you have a large time consuming script, then I would suggest splitting it up into chunks. Much better that way
TheLQ
2010-06-08 23:36:16
+2
A:
This may be of interest: ignore_user_abort()
ignore_user_abort — Set whether a client disconnect should abort script execution
However note
PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client.
Mike B
2010-06-08 23:36:36