1--TEST--
2Bug #51800 proc_open on Windows hangs forever, the right way to do it
3--SKIPIF--
4<?php
5if (strpos(PHP_OS, 'FreeBSD') !== false) {
6    die("skip Results in parallel test runner hang on FreeBSD");
7}
8?>
9--FILE--
10<?php
11$callee = __DIR__ . "/process_proc_open_bug51800_right.php";
12$php = PHP_BINARY;
13$cmd = "$php -n $callee";
14
15$status;
16$stdout = "";
17$stderr = "";
18$pipes = array();
19
20$descriptors = array(
21        0 => array("pipe", "rb"),       // stdin
22        1 => array("pipe", "wb"),       // stdout
23        2 => array("pipe", "wb")                // stderr
24        );
25
26/* create the proc file */
27$r = file_put_contents($callee, '<?php
28
29$how_much = 10000;
30
31$data0 = str_repeat("a", $how_much);
32$data1 = str_repeat("b", $how_much);
33fwrite(STDOUT, $data0);
34fwrite(STDERR, $data1);
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_right.php";
69unlink($callee);
70?>
71--EXPECTF--
72array(3) {
73  ["status"]=>
74  int(0)
75  ["stdout"]=>
76  string(10000) "a%s"
77  ["stderr"]=>
78  string(10000) "b%s"
79}
80int(10000)
81int(10000)
82