1--TEST--
2Bug #51800 proc_open on Windows hangs forever, the right way to do it
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
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===DONE===
61--CLEAN--
62<?php
63$callee = dirname(__FILE__) . "/process_proc_open_bug51800_right.php";
64unlink($callee);
65?>
66--EXPECTF--
67array(3) {
68  ["status"]=>
69  int(0)
70  ["stdout"]=>
71  string(10000) "a%s"
72  ["stderr"]=>
73  string(10000) "b%s"
74}
75int(10000)
76int(10000)
77===DONE===
78
79