Jump to content

Recommended Posts

I am developing an application that involves quite a bit of interaction with the user. After the user inputs what they want done, the php page loads, and runs the necessary processes. Most often, mysql databases are involved (all simple enough so far).

 

My question is this.. if the script is still running and the user closes their browser window, will the script be completed or does it end with the browser close. If the script does indeed stop running with the browser window close, is there a way to make it so it completes execution? The scripts generally run fairly fast (<1s) but there are some that may take longer as they can involve modifying thousands of rows of data. In the event the user has a power surge or something during their time executing the script, decides to close their browser, etc.. I don't want to be left with a job half done.

 

Any help would be greatly appreciated. Thank you.

Turns out that I most likely just found a solution to my own problem. PHP scripts generally do close after the connection with the user is aborted, but there is a way of getting around this by placing the following command at the top of the page:

 

ignore_user_abort(1);

 

That will make it so the file continues to execute in the background even after the browser window is closed. Also, adding in:

 

set_time_limit(0);

 

might also help to prevent the script from timing out if it does take a particularly long time to process. Definitely should have done more research before posting to the forums right away. At least some other people will hopefully be able to benefit from this thread.

 

For more information, see the php manual at the url below:

 

http://www.php.net/manual/ro/function.ignore-user-abort.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.