From:             chris at mysociety dot org
Operating system: n/a
PHP version:      4.4.2
PHP Bug Type:     *Web Server problem
Bug description:  SIGTERM is not handled correctly when running as a FastCGI 
server

Description:
------------
When php is running as a FastCGI server, it should handle SIGTERM and
execute a graceful shutdown, because the mod_fastcgi process manager uses
this signal to shut down excess dynamic servers. "Graceful" in this
context means that the server must finish handling any outstanding request
and then terminate its connection to the web server. Presently, PHP does
not handle SIGTERM at all in the FastCGI request loop, so that on receipt
of SIGTERM, php aborts, even if half-way through a request. This typically
results in the web server logging "Incomplete headers (0 bytes) received",
and returning "500 Internal Server Error" to the client.

I have prepared a patch for this issue, here:
http://bitter.ukcod.org.uk/~chris/tmp/20060125/php-4.3.10-fastcgi-sigterm-fix.patch
-- this is against 4.3.10, but it applies to 4.4.2 fine.

Reproduce code:
---------------
Put the following in a .php file:
<? sleep(1); print "fish"; ?>
and set it up to run under FastCGI. Set up a script to request the page in
a loop ("while : ; do wget -O/dev/null -q http://path/to/script ; done")
Then kill the PHP process (pkill php will do this under Linux). If you
catch the script in the sleep, this will result in the client getting a
500 and the web server logging a message about php failing, as describe
above.

Expected result:
----------------
No errors.

Actual result:
--------------
500 error.

-- 
Edit bug report at http://bugs.php.net/?id=36158&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36158&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36158&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36158&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36158&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36158&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36158&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36158&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36158&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36158&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36158&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36158&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36158&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36158&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36158&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36158&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36158&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36158&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36158&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36158&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36158&r=mysqlcfg

Reply via email to