|
| 1 | +--TEST-- |
| 2 | +Bug #51800 proc_open on Windows hangs forever, the right way to do it with more data |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | +$callee = dirname(__FILE__) . "/process_proc_open_bug51800_right.php"; |
| 6 | +$php = PHP_BINARY; |
| 7 | +$cmd = "$php $callee"; |
| 8 | + |
| 9 | +$status; |
| 10 | +$stdout = ""; |
| 11 | +$stderr = ""; |
| 12 | +$pipes = array(); |
| 13 | + |
| 14 | +$descriptors = array( |
| 15 | + 0 => array("pipe", "rb"), // stdin |
| 16 | + 1 => array("pipe", "wb"), // stdout |
| 17 | + 2 => array("pipe", "wb") // stderr |
| 18 | + ); |
| 19 | + |
| 20 | +/* create the proc file */ |
| 21 | +$r = file_put_contents($callee, '<?php |
| 22 | +$how_much = 1000000; |
| 23 | +
|
| 24 | +$data0 = str_repeat("a", $how_much); |
| 25 | +$data1 = str_repeat("b", $how_much); |
| 26 | +$i0 = $i1 = 0; |
| 27 | +$step = 1024; |
| 28 | +
|
| 29 | +while ($i0 < strlen($data0) && $i1 < strlen($data1)) { |
| 30 | + fwrite(STDOUT, substr($data0, $i0, $step)); |
| 31 | + fwrite(STDERR, substr($data1, $i1, $step)); |
| 32 | + $i0 += $step; |
| 33 | + $i1 += $step; |
| 34 | +} |
| 35 | +
|
| 36 | +exit(0); |
| 37 | +'); |
| 38 | + |
| 39 | +if (!$r) { |
| 40 | + die("couldn't create helper script '$callee'"); |
| 41 | +} |
| 42 | + |
| 43 | +$process = proc_open($cmd, $descriptors, $pipes); |
| 44 | + |
| 45 | +if (is_resource($process)) |
| 46 | +{ |
| 47 | + fclose($pipes[0]); |
| 48 | + |
| 49 | + while (!feof($pipes[1]) || !feof($pipes[2])) { |
| 50 | + $stdout .= fread($pipes[1], 1024); |
| 51 | + $stderr .= fread($pipes[2], 1024); |
| 52 | + } |
| 53 | + fclose($pipes[1]); |
| 54 | + fclose($pipes[2]); |
| 55 | + |
| 56 | + $status = proc_close($process); |
| 57 | +} |
| 58 | + |
| 59 | +var_dump(array( |
| 60 | + "status" => $status, |
| 61 | + "stdout" => $stdout, |
| 62 | + "stderr" => $stderr, |
| 63 | +), strlen($stdout), strlen($stderr)); |
| 64 | + |
| 65 | +?> |
| 66 | +===DONE=== |
| 67 | +--CLEAN-- |
| 68 | +<?php |
| 69 | +$callee = dirname(__FILE__) . "/process_proc_open_bug51800_right.php"; |
| 70 | +unlink($callee); |
| 71 | +?> |
| 72 | +--EXPECTF-- |
| 73 | +array(3) { |
| 74 | + ["status"]=> |
| 75 | + int(0) |
| 76 | + ["stdout"]=> |
| 77 | + string(1000000) "a%s" |
| 78 | + ["stderr"]=> |
| 79 | + string(1000000) "b%s" |
| 80 | +} |
| 81 | +int(1000000) |
| 82 | +int(1000000) |
| 83 | +===DONE=== |
| 84 | + |
0 commit comments