1--TEST-- 2Bug #69900 Commandline input/output weird behaviour with STDIO 3--FILE-- 4<?php 5 6error_reporting(E_ALL); 7 8$fl = __DIR__ . DIRECTORY_SEPARATOR . "test69900.php"; 9$max_ms = 20; 10 11$test_content = '<?php 12 13$in = fopen("php://stdin", "rb", false, stream_context_create(array("pipe" => array("blocking" => true)))); 14 15while(!feof($in)){ 16$s = fgets($in); 17 fwrite(STDOUT, $s); 18} 19 20?>'; 21file_put_contents($fl, $test_content); 22 23$descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w")); 24$pipes = array(); 25 26$process = proc_open(PHP_BINARY.' -n -f ' . $fl, $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true)); 27 28$moreThanLimit = 0; 29for($i = 0; $i < 10; $i++){ 30 fwrite($pipes[0], "hello$i\r\n"); 31 fflush($pipes[0]); 32 33 $t0 = microtime(1); 34 $s = fgets($pipes[1]); 35 $t1 = microtime(1); 36 37 echo $s; 38 39 $dt_ms = ($t1 - $t0)*1000; 40 if ($dt_ms > $max_ms) { 41 $moreThanLimit++; 42 } 43} 44 45fclose($pipes[0]); 46fclose($pipes[1]); 47 48proc_close($process); 49 50/* It is expected that the first call takes more than the limit. 51 * Allow two more to account for possible process switch, etc. */ 52if ($moreThanLimit > 3) { 53 echo "fgets() took more than $max_ms ms $moreThanLimit times\n"; 54} 55 56?> 57--CLEAN-- 58<?php 59$fl = __DIR__ . DIRECTORY_SEPARATOR . "test69900.php"; 60@unlink($fl); 61?> 62--EXPECT-- 63hello0 64hello1 65hello2 66hello3 67hello4 68hello5 69hello6 70hello7 71hello8 72hello9 73