I have an action that occurs when a user goes to a url. The action involves a tremendous amount of insert-update ot a MYSQL database and takes a good minute to finish. I was wondering if this action continues even if a user switches to another page? I would expect so since PHP is server side. But i would like to have a clear explanation on this. Anyone?
1 Answer
No, the default operation of Apache and PHP is to terminate the script when the user disconnects. This termination can happen anytime after the connection is broken, so your script may run for hours, or could die instantly. Generally the kill occurs when the script attempts to do any output.
If you need to keep the script running in spite of user disconnects, then you'll have to use
ignore_user_abort(TRUE);
3 Comments
nezgerland
I just noticed, actually even if the user attempts to go to other pages, it is not possible until the scrip completes. How can I make it so that I can give back a message to the user saying the script is being executed and the user will be notified when it is complete. The user can then go on to do other things while the script executes on our server.
Marc B
Are you using sessions? PHP will lock the session file while a script is actively using it. You'd have to
session_write_close() in your long-run script to allow other parallel requests to proceed.nezgerland
Yes I am using sessions. And not doing session_write_close(), so that is definitely interesting to me:) ..Thank you!