Bug #15529 [Com]: ap_cleanup_for_exec not used when creating

From: Date: Fri, 14 Mar 2014 13:02:43 +0000
Subject: Bug #15529 [Com]: ap_cleanup_for_exec not used when creating
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184794@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=15529&edit=1 ID: 15529 Comment by: php at braten dot be Reported by: ddhill at zk3 dot dec dot com Summary: ap_cleanup_for_exec not used when creating Status: Wont fix Type: Bug Package: Apache related Operating System: generic unix PHP Version: 4.3.3RC2-dev, PHP 5.0.0b2-dev Block user comment: N Private report: N New Comment: Related to Request #38915 Apache: system() (and similar) don't cleanup opened handles of Apache Previous Comments: ------------------------------------------------------------------------ [2003-08-13 11:56:08] iliaa@php.net Given the nature of PHP's execution architecture this is not possible/practical to implement. ------------------------------------------------------------------------ [2002-09-26 10:43:49] wez@php.net And #16548 ------------------------------------------------------------------------ [2002-09-26 10:28:44] wez@php.net Apparently related to #15642 ------------------------------------------------------------------------ [2002-02-12 15:58:24] ddhill at zk3 dot dec dot com When PHP is used as an Apache module, it does not follow the module convention when child processes are created of cleaning up the environment. PHP uses the popen() system call to do the fork/exec of a sub process. Processes created using this procedure inherit a bunch of stuff from the parent process including such things a open file descriptors and shared memory segments. This can cause a problem if the child process is intended to last longer than the duration of the PHP page that invokes it. An example of a problem that can occur would be that as long as the child process is running, it will hold open the socket port that the Apache server was listening on, even after the Apache server has been stopped. In this example, the apache will not be able to restart untill the child process has been terminated. I understand that 99.9999% of calls to system() in PHP are intended to return within the lifespan of the PHP page view. But it is reasonable (and not prohibited by the current documention) to use a php page to kick off a background task. From examinations of other apache modules (mod_cgi, fastcgi...), it would apear that the module should call ap_cleanup_for_exec() in the child process after it is forked, but prior to the exec() call. This requirement makes it impossible to use the default system popen() call. I think that a generic rewritten popen could be used that would do the same task as popen but could call the clenup routine, but am not sure how this would be integrated into the overall php build env. To reproduce this problem... create a small sleep loop script and then invoke it via php, stop the web server and then try to restart it. The server will fail to startup with the log message: [Tue Feb 12 15:44:27 2002] [crit] (48)Address already in use: make_sock: could not bind to port 80 Killing off the sleeping_loop program will allow the server to be restarted. # cat hi.php <html> <body> Hi there ! <?php exec("/bin/ksh nohup /tmp/sleeping_loop > /dev/null 2>&1 &"); ?> Execing our program ! </body> </html> # cat sleeping_loop.c #include <unistd.h> main() { setpgrp(getpid(),0); while(1) { sleep(60); } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=15529&edit=1

« previous php.bugs (#184794) next »