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