1--TEST-- 2Bug #64438 proc_open hangs with stdin/out with 4097+ bytes 3--FILE-- 4<?php 5 6error_reporting(E_ALL); 7 8if (substr(PHP_OS, 0, 3) == 'WIN') { 9 $cmd = PHP_BINARY . ' -n -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"'; 10} else { 11 $cmd = PHP_BINARY . ' -n -r \'fwrite(STDOUT, $in = file_get_contents("php://stdin")); fwrite(STDERR, $in);\''; 12} 13$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')); 14$stdin = str_repeat('*', 4097); 15 16$options = array_merge(array('suppress_errors' => true, 'bypass_shell' => false)); 17$process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options); 18 19foreach ($pipes as $pipe) { 20 stream_set_blocking($pipe, false); 21} 22$writePipes = array($pipes[0]); 23$stdinLen = strlen($stdin); 24$stdinOffset = 0; 25 26unset($pipes[0]); 27 28while ($pipes || $writePipes) { 29 $r = $pipes; 30 $w = $writePipes; 31 $e = null; 32 $n = stream_select($r, $w, $e, 60); 33 34 if (false === $n) { 35 break; 36 } elseif ($n === 0) { 37 proc_terminate($process); 38 39 } 40 if ($w) { 41 $written = fwrite($writePipes[0], substr($stdin, $stdinOffset), 8192); 42 if (false !== $written) { 43 $stdinOffset += $written; 44 } 45 if ($stdinOffset >= $stdinLen) { 46 fclose($writePipes[0]); 47 $writePipes = null; 48 } 49 } 50 51 foreach ($r as $pipe) { 52 $type = array_search($pipe, $pipes); 53 $data = fread($pipe, 8192); 54 var_dump($data); 55 if (false === $data || feof($pipe)) { 56 fclose($pipe); 57 unset($pipes[$type]); 58 } 59 } 60} 61 62?> 63===DONE=== 64--EXPECTF-- 65string(4097) "%s" 66string(4097) "%s" 67string(0) "" 68string(0) "" 69===DONE=== 70