|
Posted by Chung Leong on 06/06/06 16:12
mydejamail@yahoo.co.uk wrote:
> I have begun dabbling in php socket programming, and I have been trying
> to get the hang of the socket_select command based on the example here
> - http://www.zend.com/pecl/tutorials/sockets.php.
>
> >From examining the code it seems that if socket_select returns a value
> of >= 2 and $sock is find in the $read array will the code flow on to
> the reading portion. What is the significance of having a value of >=2
> in the $ready variable.
In the example, socket_select() is used to watch for two types of
events: new connections and availability of data. $sock is different
from the other sockets in the array in that it's not really connected
to anything. It's sort of a placeholder for a new socket. When it
becomes readable, it means there's a new incoming connection, and you
call socket_accept() to get the actual socket for that new connection.
So $ready is the number of new connections (1 or 0) plus the number of
sockets with readable data. If it's 1 and the socket is $sock, then
there are no sockets with readable data.
Navigation:
[Reply to this message]
|