1--TEST--
2Bug #46024 stream_select() doesn't return the correct number
3--SKIPIF--
4<?php if (!getenv('TEST_PHP_EXECUTABLE')) die("skip TEST_PHP_EXECUTABLE not defined"); ?>
5--FILE--
6<?php
7$php = realpath(getenv('TEST_PHP_EXECUTABLE'));
8$pipes = array();
9$proc = proc_open(
10	"$php -n -i"
11	,array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'))
12	,$pipes, dirname(__FILE__), array(), array('binary_pipes' => true)
13);
14var_dump($proc);
15if (!$proc) {
16	exit(1);
17}
18$r = array($pipes[1]);
19$w = array($pipes[0]);
20$e = null;
21$ret = stream_select($r, $w, $e, 1);
22var_dump($ret === (count($r) + count($w)));
23fread($pipes[1], 1);
24
25$r = array($pipes[1]);
26$w = array($pipes[0]);
27$e = null;
28$ret = stream_select($r, $w, $e, 1);
29var_dump($ret === (count($r) + count($w)));
30
31
32foreach($pipes as $pipe) {
33	fclose($pipe);
34}
35proc_terminate($proc);
36if (defined('SIGKILL')) {
37	proc_terminate($proc, SIGKILL);
38} else {
39	proc_terminate($proc);
40}
41proc_close($proc);
42?>
43--EXPECTF--
44resource(%d) of type (process)
45bool(true)
46bool(true)
47