From:             
Operating system: Windows
PHP version:      5.2.13
Package:          Streams related
Bug Type:         Bug
Bug description:proc_open on Windows hangs forever

Description:
------------
On Windows, if you use proc_open to open another process and if you use a
pipe for STDERR, the script will hang when trying to read from STDOUT or
STDERR if the opened process outputs a lot of data.



See the example below. The called script process.php is a simple script
which writes some data to STDOUT and STDERR:



$data = str_repeat("a", 10000); 

fwrite(STDOUT, $data);

fwrite(STDERR, $data);

exit(0);



If called as shown below, the script will hang in the loop that reads the
STDOUT pipe. The same would happen if you would read the STDERR pipe
before. If you lower the amount of data in process.php the script will run
to the end. In my tests everything below ~2000 bytes was ok, above this
value the script hang.



If you change the script below to not include the STDERR descriptor or if
you change the STDERR descriptor to a file output everything will work
fine. Also if you close the STDERR pipe before reading from STDOUT it will
work. There seems to be some deadlock.



The same script works fine on Linux.



This was tested with Windows Server 2008, IIS, PHP 5.2.13. But I have seen
this on other Windows configurations as well.

Test script:
---------------
<?php

$cmd = "\"C:/Program Files/php/php.exe\" process.php";



$status;

$stdout = "";

$stderr = "";

$pipes = array();



$descriptors = array(

        0 => array("pipe", "r"),        // stdin

        1 => array("pipe", "w"),        // stdout

        2 => array("pipe", "w")         // stderr

        );

$process = proc_open($cmd, $descriptors, $pipes);

        

if (is_resource($process))

{

        fclose($pipes[0]);

        

        while (!feof($pipes[1]))

                $stdout .= fread($pipes[1], 1024);

        fclose($pipes[1]);

        

        while (!feof($pipes[2]))

                $stderr .= fread($pipes[2], 1024);

        fclose($pipes[2]);

        

        $status = proc_close($process);

}



print_r(array(

        "status" => $status,

        "stdout" => $stdout,

        "stderr" => $stderr,

));

?>


-- 
Edit bug report at http://bugs.php.net/bug.php?id=51800&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51800&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51800&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51800&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51800&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51800&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51800&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51800&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51800&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51800&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51800&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51800&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51800&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51800&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51800&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51800&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51800&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51800&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51800&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51800&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51800&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51800&r=mysqlcfg

Reply via email to