php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24858 proc_open() leaves zombie processes if user cancels page load
Submitted: 2003-07-29 13:51 UTC Modified: 2003-08-01 14:51 UTC
From: jr-php2 at quo dot to Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 4.3.3RC2-dev OS: Red Hat Linux 9.0, kernel 2.4.21
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jr-php2 at quo dot to
New email:
PHP Version: OS:

 

 [2003-07-29 13:51 UTC] jr-php2 at quo dot to
Description:
------------
Apache version: 1.3.28
PHP version: 4.3.2, used as a CGI binary:
./configure --prefix=/usr/local/php-cgi --enable-track-vars --with-mysql --with-zlib --enable-discard-path

I have found that if page loading is cancelled by the user (e.g. by closing the Internet Explorer window) before fclose() & proc_close() are called, a zombie process is left behind.

Try the code below (save it as 'testx.cgi'). During normal execution, you'll see this:

27551 ?        S      0:00 /usr/local/php-cgi/bin/php testx.cgi
22800 ?        Z      0:00 [ls <defunct>]

If you let the page load completely, both processes go away from the process list.

If, however, you close the browser window before the sleep() call finishes, about 70% of the time a zombie process is left behind:

27551 ?        Z      0:00 [testx.cgi <defunct>]

I have to restart Apache (1.3.28) to kill this process.

Reproduce code:
---------------
#!/usr/local/php-cgi/bin/php
<?php
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/dev/null", "a"), // stderr is a file to write to
);
$process = proc_open('/bin/ls -al /tmp', $descriptorspec, $pipes);
if (!is_resource($process)) die("Error: proc_open failed");

sleep(10);

fclose($pipes[0]);

fpassthru($pipes[1]);
fclose($pipes[1]);

proc_close($process);
?>

Expected result:
----------------
There should be no zombie process left over when the user cancels the page load.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-29 14:36 UTC] jr-php2 at quo dot to
FYI, I tried adding a "ignore_user_abort(1);" call to the top of the script but it did not help. I guess ignore_user_abort() probably has no effect when PHP is used as a CGI binary?
 [2003-07-30 02:42 UTC] jr-php2 at quo dot to
Same problem exists in php4-STABLE-200307300530.
 [2003-08-01 14:51 UTC] jr-php2 at quo dot to
Good news:

I found I couldn't reproduce the problem after downgrading Apache to 1.3.27. Then I came across this bug report for Apache 1.3.28:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21737

I applied the second patch there, and so far haven't had any more lingering zombie processes.

Why I could only reproduce the problem when I used proc_open() remains a mystery... Sorry for the false alarm.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 04:01:27 2025 UTC