Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a PHP script executed by apache killed when the HTTP connection dies?

Tags:

php

apache

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?

like image 561
Udi Wertheimer Avatar asked May 02 '11 16:05

Udi Wertheimer


People also ask

Does Apache work with PHP?

PHP support can be added to a number of web servers (IIS, Xitami, and so on), but most commonly Apache HTTP Server is used. Click here for information on how to install and configure Apache 2.2. The PHP engine. The supported version is PHP5.


1 Answers

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.

like image 137
Lightness Races in Orbit Avatar answered Sep 18 '22 14:09

Lightness Races in Orbit