From:             [EMAIL PROTECTED]
Operating system: generic unix 
PHP version:      4.1.1
PHP Bug Type:     Apache related
Bug description:  ap_cleanup_for_exec not used when creating 


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 bug report at http://bugs.php.net/?id=15529&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=15529&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=15529&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=15529&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=15529&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15529&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=15529&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=15529&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=15529&r=submittedtwice

Reply via email to