|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15529 ap_cleanup_for_exec not used when creating
Submitted: 2002-02-12 15:58 UTC Modified: 2003-08-13 11:56 UTC
Avg. Score:4.5 ± 0.7
Reproduced:22 of 23 (95.7%)
Same Version:4 (18.2%)
Same OS:13 (59.1%)
From: ddhill at zk3 dot dec dot com Assigned:
Status: Wont fix Package: Apache related
PHP Version: 4.3.3RC2-dev, PHP 5.0.0b2-dev OS: generic unix
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-02-12 15:58 UTC] 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
Hi there !
<?php exec("/bin/ksh nohup /tmp/sleeping_loop > /dev/null 2>&1 &"); ?>
Execing our program !

# cat sleeping_loop.c

#include <unistd.h>
main() {
    while(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-26 10:28 UTC]
Apparently related to #15642
 [2002-09-26 10:43 UTC]
And #16548
 [2003-08-13 11:56 UTC]
Given the nature of PHP's execution architecture this is not possible/practical to implement.
 [2014-03-14 13:02 UTC] php at braten dot be
Related to Request #38915 	Apache: system() (and similar) don't cleanup opened handles of Apache
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Sep 21 13:01:24 2023 UTC