|
Posted by mydejamail on 06/07/06 10:38
This appears to imply that socket_select can only notify just 1 new
socket, and that if more than 1 new connections have been made, the
additional connections can only be detected on the next pass - is it
so?
Concerning the $sock value, the $read[0] = $sock at the top of the loop
always makes $sock an element of the array, so I would expect
in_array($sock, $read) to always return true. So I would take it that
socket_select removes or modifies $read[0], or any instances of $read
where $read[x] = $sock if there is no new connection, right?
Chung Leong wrote:
> 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]
|