|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-03 02:16 UTC] basant dot kukreja at sun dot com
Description: ------------ php fastcgi parent process calls sapi_startup but it doesn't call php_module_shutdown before exiting. The result of this is : 1) php behavior is different when running inside apache and inside fastcgi. When running inside apache, parent apache process calls php_module_shutdown. 2) Since php fastcgi parent doesn't call php_module_shutodown, it doesn't give modules like apc to do proper cleanup chance. Note that apc creates semaphores and it needs to know if parent process is shutting down to cleanup semaphores. Here is the APC bug link : http://pecl.php.net/bugs/bug.php?id=5280 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 23:00:01 2025 UTC |
Suggested fix : Php fastcgi parent process install signals and inside signal handler it calls exit. I think it is not wise to call complicated stuff like php_module_shutdown inside signal handler so in my suggested fix, I set the variable exitsignal to 1. When parent will come out of wait call, it should first invoke cleanup functions and then call exit. --- sapi/cgi/cgi_main.c_orig 2008-04-09 02:16:40.000000000 -0700 +++ sapi/cgi/cgi_main.c 2008-07-02 18:56:44.968570000 -0700 @@ -103,6 +103,12 @@ */ static int parent = 1; +/* Did parent received exit signals SIG_TERM/SIG_INT/SIG_QUIT */ +static int exitsignal = 0; + +/* Is Parent waiting for children to exit */ +static int parentwaiting = 0; + /** * Process group */ @@ -1151,9 +1157,13 @@ /* Kill all the processes in our process group */ kill(-pgroup, SIGTERM); #endif - /* We should exit at this point, but MacOSX doesn't seem to */ - exit(0); + if (parent && parentwaiting) { + exitsignal = 1; + } + else { + exit(0); + } } #endif @@ -1557,8 +1567,15 @@ #ifdef DEBUG_FASTCGI fprintf(stderr, "Wait for kids, pid %d\n", getpid()); #endif + parentwaiting = 1; while (wait(&status) < 0) { } + if (exitsignal) { + SG(server_context) = NULL; + php_module_shutdown(TSRMLS_C); + sapi_shutdown(); + exit(0); + } running--; } }