1

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
  • in such a case, why don't you run the task in the background. then the users actions are irrelevant to he running of the script. Commented May 6, 2012 at 21:02

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
Yes I am using sessions. And not doing session_write_close(), so that is definitely interesting to me:) ..Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.