1--TEST--
2Bug #51800 proc_open on Windows hangs forever, the right way to do it with more data
3--FILE--
4<?php
5$callee = __DIR__ . "/process_proc_open_bug51800_right2.php";
6$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
7$cmd = "$php -n " . escapeshellarg($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
29while ($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
36exit(0);
37');
38
39if (!$r) {
40    die("couldn't create helper script '$callee'");
41}
42
43$process = proc_open($cmd, $descriptors, $pipes);
44
45if (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
59var_dump(array(
60        "status" => $status,
61        "stdout" => $stdout,
62        "stderr" => $stderr,
63), strlen($stdout), strlen($stderr));
64
65?>
66--CLEAN--
67<?php
68$callee = __DIR__ . "/process_proc_open_bug51800_right2.php";
69unlink($callee);
70?>
71--EXPECTF--
72array(3) {
73  ["status"]=>
74  int(0)
75  ["stdout"]=>
76  string(1000000) "a%s"
77  ["stderr"]=>
78  string(1000000) "b%s"
79}
80int(1000000)
81int(1000000)
82