Reply to Understanding socket_select routine

Your name:

Reply:


Posted by mydejamail on 11/26/06 11:49

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.

I know that this may be due to some lack of familiarity with sockets
and PHPs approach to them, but can anyone enlighten me on the value in
$ready variable and how the $read array passed to the socket_select
variable is modified?

while (true) {
// Setup clients listen socket for reading
$read[0] = $sock;
for ($i = 0; $i < $max_clients; $i++)
{
if ($client[$i]['sock'] != null)
$read[$i + 1] = $client[$i]['sock'] ;
}
// Set up a blocking call to socket_select()
$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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация