1--TEST--
2proc_open() regression test 1 (proc_open() leak)
3--FILE--
4<?php
5$pipes = array(1, 2, 3);
6$orig_pipes = $pipes;
7$php = getenv('TEST_PHP_EXECUTABLE');
8if ($php === false) {
9    die("no php executable defined");
10}
11$proc = proc_open(
12    "$php -n",
13    array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')),
14    $pipes, getcwd(), array(), array()
15);
16if ($proc === false) {
17    print "something went wrong.\n";
18}
19var_dump($pipes);
20stream_set_blocking($pipes[1], FALSE);
21$test_string = "yay!\n";
22fwrite($pipes[0], $test_string);
23fflush($pipes[0]);
24fclose($pipes[0]);
25$cnt = '';
26$n=0;
27for ($left = strlen($test_string); $left > 0;) {
28    if (++$n >1000) {
29      print "terminated after 1000 iterations\n";
30      break;
31    }
32    $read_fds = array($pipes[1]);
33    $write_fds = NULL;
34    $exp_fds = NULL;
35    $retval = stream_select($read_fds, $write_fds, $exp_fds, 5);
36    if ($retval === false) {
37        print "select() failed\n";
38        break;
39    }
40    if ($retval === 0) {
41        print "timed out\n";
42        break;
43    }
44    $buf = fread($pipes[1], 1024);
45    $cnt .= $buf;
46    $left -= strlen($buf);
47}
48var_dump($cnt);
49fclose($pipes[1]);
50proc_close($proc);
51var_dump($orig_pipes);
52?>
53--EXPECTF--
54array(2) {
55  [0]=>
56  resource(%d) of type (stream)
57  [1]=>
58  resource(%d) of type (stream)
59}
60string(5) "yay!
61"
62array(3) {
63  [0]=>
64  int(1)
65  [1]=>
66  int(2)
67  [2]=>
68  int(3)
69}
70