1--TEST--
2Bug #46024 stream_select() doesn't return the correct number
3--SKIPIF--
4<?php
5if (!getenv('TEST_PHP_EXECUTABLE')) die("skip TEST_PHP_EXECUTABLE not defined");
6// Terminating the process may cause a bailout while writing out the phpinfo,
7// which may leak a temporary hash table. This does not seems worth fixing.
8if (getenv('SKIP_ASAN')) die("skip Test may leak");
9?>
10--FILE--
11<?php
12$php = realpath(getenv('TEST_PHP_EXECUTABLE'));
13$pipes = array();
14$proc = proc_open(
15    "$php -n -i"
16    ,array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'))
17    ,$pipes, __DIR__, array(), array()
18);
19var_dump($proc);
20if (!$proc) {
21    exit(1);
22}
23$r = array($pipes[1]);
24$w = array($pipes[0]);
25$e = null;
26$ret = stream_select($r, $w, $e, 1);
27var_dump($ret === (count($r) + count($w)));
28fread($pipes[1], 1);
29
30$r = array($pipes[1]);
31$w = array($pipes[0]);
32$e = null;
33$ret = stream_select($r, $w, $e, 1);
34var_dump($ret === (count($r) + count($w)));
35
36
37foreach($pipes as $pipe) {
38    fclose($pipe);
39}
40proc_terminate($proc);
41if (defined('SIGKILL')) {
42    proc_terminate($proc, SIGKILL);
43} else {
44    proc_terminate($proc);
45}
46proc_close($proc);
47?>
48--EXPECTF--
49resource(%d) of type (process)
50bool(true)
51bool(true)
52