From:             pajoye
Operating system: windows
PHP version:      Irrelevant
Package:          Filesystem function related
Bug Type:         Bug
Bug description:proc_open hangs with stdin/out with 2048+ bytes

Description:
------------
The stream used to read data from stdin/out/err hangs if the data passed is

getting larger than 2048, under certain circumstances. 

Test script:
---------------
error_reporting(E_ALL);

$cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\'));
fwrite(STDERR, $in);"';
$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe',
'w'));
$stdin = str_repeat('*', 1024 * 16) . '!';
$stdin = str_repeat('*', 2049 );

$options = array_merge(array('suppress_errors' => true, 'binary_pipes' =>
true, 'bypass_shell' => false));
$process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(),
$options);

foreach ($pipes as $pipe) {
    stream_set_blocking($pipe, false);
}
$writePipes = array($pipes[0]);
$stdinLen = strlen($stdin);
$stdinOffset = 0;

unset($pipes[0]);

while ($pipes || $writePipes) {
    $r = $pipes;
    $w = $writePipes;
    $e = null;
    $n = stream_select($r, $w, $e, 60);

    if (false === $n) {
        break;
    } elseif ($n === 0) {
        proc_terminate($process);

    }
    if ($w) {
        $written = fwrite($writePipes[0], (binary)substr($stdin,
$stdinOffset), 8192);
        if (false !== $written) {
            $stdinOffset += $written;
        }
        if ($stdinOffset >= $stdinLen) {
            fclose($writePipes[0]);
            $writePipes = null;
        }
    }

    foreach ($r as $pipe) {
        $type = array_search($pipe, $pipes);
        $data = fread($pipe, 8192);
        if (false === $data || feof($pipe)) {
            fclose($pipe);
            unset($pipes[$type]);
        }
    }
}


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

Reply via email to