From:             phil at concretecomputing dot co dot uk
Operating system: sun os 
PHP version:      4.3.1
PHP Bug Type:     Filesystem function related
Bug description:  proc_close() sometimes returns -1 when called process exited with 
status of 0

I'm trying to run a command via proc_open(). The command always succeeds
(exits with status of 0), so I would expect that proc_close() would always
return 0. Most of the time it does, but sometimes it returns -1.

Here is a script which reproduces the problem. On my system, if you run
the script many times, most times the status reported will be 0, but
occasionally it will be -1.

<?

$inputArray = 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("pipe", "w")                             // stderr is a pipe
that the child will write to
);

$process = proc_open("ps -ef", $inputArray, $outputArray);               


if (is_resource($process)) {

  fclose($outputArray[0]);

  // Grab the output
  $output="";
  while(!feof($outputArray[1])) {
    $output .= fgets($outputArray[1], 1024);       
  }

  // Extract any error output
  $errorOutput = "";
  while(!feof($outputArray[2])) {
    $errorOutput .= fgets($outputArray[2], 1024);
  }

  // It is important that you close any pipes before calling proc_close()
in order to avoid a deadlock
  fclose($outputArray[1]);
  fclose($outputArray[2]);

  $status = proc_close($process);    

  echo "proc_close() return result: $status<br>\n";            
  echo "ps error output: [$errorOutput]<br>\n";
  echo "ps output: [$output]<br>\n";                 
}

echo "Done<br>\n";

?>


PHP is compiled as follows:

'./configure' '--with-apxs=/usr/local/apache1.3.27-nerens3.4/bin/apxs'
'--without-mysql' '--enable-track-vars' '--enable-sigchild'
'--with-oci8=/opt/oracle/product/9.0.1' '--enable-apc' '--with-xml'
'--with-expat-dir=/usr/local/expat' '--with-zlib=/usr/local/zlib'
'--with-curl=/usr/local/curl' '--with-mhash=/usr/local/mhash'
'--with-mcrypt=/usr/local/libmcrypt' 

I have tried to have a look at what is going on using truss and I think it
may be caused by another function within php doing a wait() and getting
the exit status for the child so that the wait() in proc_close returns
with ECHLD.

While testing using the above script, I have found that if I add a call to
sleep after the proc_open() call then proc_close() _always_ returns -1
(and the sleep() call has no effect)
-- 
Edit bug report at http://bugs.php.net/?id=22999&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22999&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22999&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22999&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22999&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22999&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22999&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22999&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22999&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22999&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22999&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22999&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22999&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22999&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22999&r=gnused

Reply via email to