Skip to content

Commit 2021a58

Browse files
authored
Reintroduce proc_open_multiplex.phpt (GH-17192)
The main intent of the test was to show the changed behavior on Windows; previously, `stream_select()` would return immediately there, reporting all pipes as ready; now, it only returns if at least one pipe is actually ready. The original test case was overspecified; of course, we cannot assume that the pipes are ready one after the other; depending on the concrete `select(2)` implementation and the system scheduler, minor differences are to be expected. Thus we relax the test expectations, and now require that not all pipes are reported ready after a single `stream_select()` call, and that the output contains all strings. We also ensure that `stream_select()` doesn't fail (for whatever reason). And in case of the test expectations not being met, we also output some diagnostics (most notably the output that has already been read).
1 parent ef4fabf commit 2021a58

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Multiplexing of child output
3+
--FILE--
4+
<?php
5+
$php = getenv("TEST_PHP_EXECUTABLE");
6+
$desc = [
7+
["null"],
8+
["pipe", "w"],
9+
["null"]
10+
];
11+
$read_pipes = [];
12+
for ($i = 0; $i < 10; $i++) {
13+
$procs[] = proc_open([$php, "-r", "usleep(10000 * (10 - $i)); echo 'hello$i';"], $desc, $pipes);
14+
$read_pipes[] = $pipes[1];
15+
}
16+
$out = [];
17+
$rset = $read_pipes;
18+
$wset = null;
19+
$eset = null;
20+
while (!empty($read_pipes) && ($selected = stream_select($rset, $wset, $eset, 1)) > 0) {
21+
foreach ($rset as $pipe) {
22+
if ($selected === 10) {
23+
echo "stream_select() reported all pipes as ready\n";
24+
echo "Read:\n", implode("\n", $out);
25+
exit;
26+
}
27+
$out[] = fread($pipe, 6);
28+
unset($read_pipes[array_search($pipe, $read_pipes)]);
29+
}
30+
$rset = $read_pipes;
31+
}
32+
if ($selected === false) {
33+
echo "stream_select() failed\n";
34+
echo "Read:\n", implode("\n", $out);
35+
exit;
36+
}
37+
sort($out);
38+
echo "Read:\n", implode("\n", $out);
39+
?>
40+
--EXPECT--
41+
Read:
42+
hello0
43+
hello1
44+
hello2
45+
hello3
46+
hello4
47+
hello5
48+
hello6
49+
hello7
50+
hello8
51+
hello9

0 commit comments

Comments
 (0)