1--TEST--
2Bug #51800 proc_open on Windows hangs forever, the right way to do it
3--FILE--
4<?php
5$callee = __DIR__ . "/process_proc_open_bug51800_right.php";
6$php = PHP_BINARY;
7$cmd = "$php -n $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
23$how_much = 10000;
24
25$data0 = str_repeat("a", $how_much);
26$data1 = str_repeat("b", $how_much);
27fwrite(STDOUT, $data0);
28fwrite(STDERR, $data1);
29
30exit(0);
31');
32
33if (!$r) {
34    die("couldn't create helper script '$callee'");
35}
36
37$process = proc_open($cmd, $descriptors, $pipes);
38
39if (is_resource($process))
40{
41        fclose($pipes[0]);
42
43        while (!feof($pipes[1]) || !feof($pipes[2])) {
44                $stdout .= fread($pipes[1], 1024);
45                $stderr .= fread($pipes[2], 1024);
46        }
47        fclose($pipes[1]);
48        fclose($pipes[2]);
49
50        $status = proc_close($process);
51}
52
53var_dump(array(
54        "status" => $status,
55        "stdout" => $stdout,
56        "stderr" => $stderr,
57), strlen($stdout), strlen($stderr));
58
59?>
60--CLEAN--
61<?php
62$callee = __DIR__ . "/process_proc_open_bug51800_right.php";
63unlink($callee);
64?>
65--EXPECTF--
66array(3) {
67  ["status"]=>
68  int(0)
69  ["stdout"]=>
70  string(10000) "a%s"
71  ["stderr"]=>
72  string(10000) "b%s"
73}
74int(10000)
75int(10000)
76