naifwonder Posted December 15, 2009 Share Posted December 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185262-php-script-running-after-browser-is-closed/ Share on other sites More sharing options...
naifwonder Posted December 15, 2009 Author Share Posted December 15, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185262-php-script-running-after-browser-is-closed/#findComment-977994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.