1--TEST--
2Bug #51800 proc_open on Windows hangs forever
3--SKIPIF--
4<?php
5	echo 'skip expected to fail or take too long';
6	if (getenv("SKIP_SLOW_TESTS")) {
7		die("skip slow test");
8	}
9?>
10--XFAIL--
11pipes have to be read/written simultaneously
12--FILE--
13<?php
14/* This is the wrong way to do it. The parent will block till it has read all the STDIN.
15The smaller the pipe buffer is, the longer it will take. It might even pass at the end,
16after taking inappropriately long. Pipes have to be read simultaneously in smaller chunks,
17so then the pipe buffer is emptied more often and the child has chance to continue its
18write. The behaviour might look some better if write/read in a separate thread, however
19this is much more resource greedy and complexer to integrate into the user script. */
20
21$callee = dirname(__FILE__) . "/process_proc_open_bug51800.php";
22$php = PHP_BINARY;
23$cmd = "$php $callee";
24
25$status;
26$stdout = "";
27$stderr = "";
28$pipes = array();
29
30$descriptors = array(
31        0 => array("pipe", "rb"),       // stdin
32        1 => array("pipe", "wb"),       // stdout
33        2 => array("pipe", "wb")                // stderr
34        );
35
36/* create the proc file */
37$r = file_put_contents($callee, '<?php
38
39$how_much = 10000;
40
41$data0 = str_repeat("a", $how_much);
42$data1 = str_repeat("b", $how_much);
43fwrite(STDOUT, $data0);
44fwrite(STDERR, $data1);
45
46exit(0);
47');
48
49if (!$r) {
50	die("couldn't create helper script '$callee'");
51}
52
53$process = proc_open($cmd, $descriptors, $pipes);
54
55if (is_resource($process))
56{
57        fclose($pipes[0]);
58
59	while (!feof($pipes[1]))
60		$stdout .= fread($pipes[1], 1024);
61	fclose($pipes[1]);
62
63	while (!feof($pipes[2]))
64		$stderr .= fread($pipes[2], 1024);
65	fclose($pipes[2]);
66
67        $status = proc_close($process);
68}
69
70var_dump(array(
71        "status" => $status,
72        "stdout" => $stdout,
73        "stderr" => $stderr,
74), strlen($stdout), strlen($stderr));
75
76?>
77===DONE===
78--CLEAN--
79<?php
80$callee = dirname(__FILE__) . "/process_proc_open_bug51800.php";
81unlink($callee);
82?>
83--EXPECTF--
84array(3) {
85  ["status"]=>
86  int(0)
87  ["stdout"]=>
88  string(10000) "a%s"
89  ["stderr"]=>
90  string(10000) "b%s"
91}
92int(10000)
93int(10000)
94===DONE===
95