The way the document describes socket_select()'s handling of sockets polled for read is rather obscure.
It says that it checks to see if reading would not "block," but the overall description of socket_select() says it checks for a change in blocking status. Unfortunately, these are in conflict.
If a socket already has data in the buffer, calling socket_select() on that socket would never return (assuming null timeout), and would block forever. :-( This is because the blocking status wouldn't change. It simply stays "non-blocking"
It is important to remember NOT to select() on a socket which may already have data available.
An example...
<?php
$done = false;
$n = 0;
do{
$tmp = 0;
$r = $w = $e = array();
$r = array($socket);
socket_select($r,$w,$e,null);
$n = socket_recv($socket, $tmp, 1024, 0);
}while(!$done);
?>
This MAY NOT work... socket_select() is always being called... but we may have data in the input buffer.
We need to ensure that the last time we read, nothing was read... (empty buffer)
<?php
$done = false;
$n = 0;
do{
$tmp = 0;
$r = $w = $e = array();
$r = array($socket);
if($n === 0) socket_select($r,$w,$e,null);
$n = socket_recv($socket, $tmp, 1024, 0);
}while(!$done);
?>