The test currently assumes that we'll first read the data of
stdout and stderr and then see eof on stdout and stderr. However
we could also read stdout, see eof on stdout, read stderr and see
eof on stderr, depending on timing.
Avoid output ordering issues by collecting events into a per-pipe
array, so interleaving is not visible.
unset($pipes[0]);
+$pipeEvents = [];
while ($pipes || $writePipes) {
$r = $pipes;
$w = $writePipes;
foreach ($r as $pipe) {
$type = array_search($pipe, $pipes);
$data = fread($pipe, 8192);
- var_dump($data);
if (false === $data || feof($pipe)) {
+ $pipeEvents[(int)$pipe][] = "Closing pipe";
fclose($pipe);
unset($pipes[$type]);
+ } else {
+ $pipeEvents[(int)$pipe][] = "Read " . strlen($data) . " bytes";
}
}
}
+var_dump($pipeEvents);
+
?>
===DONE===
--EXPECTF--
-string(4097) "%s"
-string(4097) "%s"
-string(0) ""
-string(0) ""
+array(2) {
+ [%d]=>
+ array(2) {
+ [0]=>
+ string(15) "Read 4097 bytes"
+ [1]=>
+ string(12) "Closing pipe"
+ }
+ [%d]=>
+ array(2) {
+ [0]=>
+ string(15) "Read 4097 bytes"
+ [1]=>
+ string(12) "Closing pipe"
+ }
+}
===DONE===