Posted by Sjoerd on 11/05/74 11:50
mydejamail@yahoo.co.uk schreef:
> >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.
$ready contains the number of sockets on which the state has changed.
The code which you posted goes through the loop $ready times, accepting
$sock and putting the result in an empty $client[$i]['sock'].
This is a hard example. It is probably best to try out socket_select
with just one socket. Try what it does and what its return value is.
> $ready = socket_select($read,null,null,null);
> /* if a new connection is being made add it to the client array */
> if (in_array($sock, $read)) {
> for ($i = 0; $i < $max_clients; $i++)
> {
> if ($client[$i]['sock'] == null) {
> $client[$i]['sock'] = socket_accept($sock);
> break;
> }
> elseif ($i == $max_clients - 1)
> print ("too many clients")
> }
> if (--$ready <= 0)
> continue;
> } // end if in_array
[Back to original message]
|