Reputation: 293
I'm running a standard configuration of Apache with PHP. I'm wondering what happens when a client requests a page that causes a PHP script to execute, then the client kills the request from the server, before the script finishes. Does Apache kill the script in some way, or is it allowed to complete nonetheless?
Upvotes: 6
Views: 2048
Reputation: 385164
The documentation answers this:
When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button. If the PHP-imposed time limit (see set_time_limit()) is hit, the TIMEOUT state flag is turned on.
You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate.
If you want to tell the remote client that the script is complete, but continue post-request processing nonetheless, look at this question/answer.
Upvotes: 8