|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-30 11:34 UTC] gabriel at oxeva dot fr
Description: ------------ Context: When running PHP in FastCGI mode with a fastCGI apache module (such a mod_fcgid), all is running fine when PHP_FCGI_CHILDREN unset : only 1 process spawned. When using PHP_FCGI_CHILDREN=n, the PHP parent process forks n childs, and the parent acts as a manager between the child processes, wait()ing to respawn them if they are killed or exit. The problem happens when the FastCGI process manager handled by the apache module has to kill the parent PHP process (it only knows the parent's PID) for any reason such as idle timeout, max lifetime, etc. Problem: While the PHP parent process is properly killed by the FastCGI process manager, the children aren't killed, but instead stay alive, waiting for a new request which will never come (because the socket shared with the parent is removed at the same time parent is killed). Reproduce code: --------------- This is not always reproducible, as the problem only happens when the php FastCGI processes are busy. The only way the kill these "orphan" children, is using the signal 9 on them (to interrupt the blocking read() syscall they are executing) Expected result: ---------------- In the example, the fastCGI process manager spawns php by fork()ing then exec()ing /path/to/php , with environment PHP_FCGI_CHILDREN=2 PHP parent process is PID 10, and it forks itself 2 childs, PID 11 and 12. When killing PID 10 with normal signal 15, and the whole php processes are under load, PID 10 is killed, but the 2 children PID 11 and 12 stay alive. The expected result is that when the PHP parent process is killed, all the children in any processing state are killed too. Actual result: -------------- strace of children processes (PID 11 and 12) still alive gives : # strace -p 11 Process 11 attached - interrupt to quit read(3, <unfinished ...> PID 12 give the same result. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
I hope the bug is fixed in CVS HEAD, PHP_5_2 (not in 5.2.1) and PHP_4_4 (not in 4.4.5). The patch for PHP_5_2 folows: Index: sapi/cgi/cgi_main.c =================================================================== RCS file: /repository/php-src/sapi/cgi/cgi_main.c,v retrieving revision 1.267.2.15.2.22 diff -u -p -d -r1.267.2.15.2.22 cgi_main.c --- sapi/cgi/cgi_main.c 15 Feb 2007 12:33:16 -0000 1.267.2.15.2.22 +++ sapi/cgi/cgi_main.c 16 Feb 2007 11:16:39 -0000 @@ -355,18 +355,14 @@ static int sapi_cgi_send_headers(sapi_he static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { - uint read_bytes=0, tmp_read_bytes; -#if PHP_FASTCGI - char *pos = buffer; -#endif + int read_bytes=0, tmp_read_bytes; count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes < count_bytes) { #if PHP_FASTCGI if (fcgi_is_fastcgi()) { fcgi_request *request = (fcgi_request*) SG(server_context); - tmp_read_bytes = fcgi_read(request, pos, count_bytes - read_bytes); - pos += tmp_read_bytes; + tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes); } else { tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes); }