I've got this PHP script i am starting in my web browser. It reads a lot of data and writes it to a database. What is happening
when i click BACK in the browser (or go to another link/page)?
close the web browser? Will the the script run in the background until it's finished?
It should continue running until finished unless the php.ini setting ignore_user_abort is set (disabled by default). Since ignore_user_abort is disabled by default, the default PHP behavior is to terminate the script prior to completion if it detects the user has gone away. To change this, call ignore_user_abort(true); at the beginning of your script.
That said, in somewhat short lived scripts, PHP may not detect the user has gone away until the processing finishes even if the user disconnected several seconds earlier.
See ignore_user_abort() which has an example script that shows it will continue running after the user disconnects.
Also note, PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush().
If you had started a session, the session file may not be closed (unlocked) until the script finishes running so future page loads by the same user that attempt to start a session may hang until the script with the session lock finishes. To avoid this, you can call session_write_close when session information is no longer needed if you plan on running a script for an extended period of time.
This reference on connection handling in php should also be of interest to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With