Simple stream_select wrapper.. Returns the first stream in the array, and sets parameter 2 to the key (So that it is easy to identify what received data):
<?php
function select($array, &$vkey, $timeout=0){
$select = array();
$null = NULL;
foreach($array as $key => $sock){
$x = count($select);
$select[$x] = $sock;
$keys[$x] = $key;
}
if(stream_select($select, $null, $null, $timeout)){
foreach($keys as $key){
if($array[$key] == $select[0]){
$vkey = $key;
return($select[0]);
}
}
}
}
$streams = array("foo" => $stream_one, "bar" => $stream_two); if($new = select($streams, $key, 60)){ echo $key.":".stream_get_line($new, 2048)."\n";
}
?>