1--TEST--
2Bug #64770 stream_select() fails with pipes from proc_open()
3--FILE--
4<?php
5
6$descs = array(
7	0 => array('pipe', 'r'), // stdin
8	1 => array('pipe', 'w'), // stdout
9	2 => array('pipe', 'w'), // strerr
10);
11
12$other_opts = array('suppress_errors' => false, 'binary_pipes' => true);
13
14$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
15$p = proc_open($cmd, $descs, $pipes, '.', NULL, $other_opts);
16
17if (is_resource($p)) {
18	$data = '';
19
20	while (1) {
21		$w = $e = NULL;
22		$n = stream_select($pipes, $w, $e, 300);
23
24		if ($n === false) {
25			echo "no streams \n";
26			break;
27		} else if ($n === 0) {
28			echo "process timed out\n";
29			proc_terminate($p, 9);
30			break;
31		} else if ($n > 0) {
32			$line = fread($pipes[1], 8192);
33			if (strlen($line) == 0) {
34				/* EOF */
35				break;
36			}
37			$data .= $line;
38		}
39	}
40	var_dump(strlen($data));
41
42	$ret = proc_close($p);
43	var_dump($ret);
44} else {
45	echo "no process\n";
46}
47?>
48==DONE==
49--EXPECTF--
50int(%d)
51int(0)
52==DONE==
53