Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions ext/standard/tests/general_functions/proc_open_multiplex.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
Multiplexing of child output
--FILE--
<?php
$php = getenv("TEST_PHP_EXECUTABLE");
$desc = [
["null"],
["pipe", "w"],
["null"]
];
$read_pipes = [];
for ($i = 0; $i < 10; $i++) {
$procs[] = proc_open([$php, "-r", "usleep(100000 * (10 - $i)); echo 'hello$i';"], $desc, $pipes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really need to take the whole second (10 x 100ms) to test this? I think it should work for shorter interval to test what is tested here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reduced to 10 * 10ms, and CI is still green.

$read_pipes[] = $pipes[1];
}
$out = [];
$rset = $read_pipes;
$wset = null;
$eset = null;
while (!empty($read_pipes) && ($selected = stream_select($rset, $wset, $eset, 2)) > 0) {
foreach ($rset as $pipe) {
if ($selected === 10) {
echo "stream_select() reported all pipes as ready\n";
echo "Read:\n", implode("\n", $out);
exit;
}
$out[] = fread($pipe, 6);
unset($read_pipes[array_search($pipe, $read_pipes)]);
}
$rset = $read_pipes;
}
if ($selected === false) {
echo "stream_select() failed\n";
echo "Read:\n", implode("\n", $out);
exit;
}
sort($out);
echo "Read:\n", implode("\n", $out);
?>
--EXPECT--
Read:
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
Loading