| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2003-04-01 04:17 UTC] phil at concretecomputing dot co dot uk
 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 08:00:01 2025 UTC | 
We have the same issue with pclose() Testcase: <?php $fp = popen("ls","r"); if ($fp) { while(! feof($fp)) { fgets($fp,1024); } $status = pclose($fp); print "pclose: status=$status\n"; } ?> Most of the time $status is -1, sometimes 0. PHP-4.3.2RC1, Solaris 7, --enable-sigchild PHP is compiled with --enable-sigchild because the oracle client is needed too, this was recommended in former bug descriptions. Is this still the case for oracle?