1--TEST-- 2Multiplexing 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 = []; 12for ($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; 20while (!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} 32if ($selected === false) { 33 echo "stream_select() failed\n"; 34 echo "Read:\n", implode("\n", $out); 35 exit; 36} 37sort($out); 38echo "Read:\n", implode("\n", $out); 39?> 40--EXPECT-- 41Read: 42hello0 43hello1 44hello2 45hello3 46hello4 47hello5 48hello6 49hello7 50hello8 51hello9 52