socket_select() problems?
| From: | Rasmus Lerdorf | Date: | Sun, 02 Jun 2002 01:07:17 +0000 |
| Subject: | socket_select() problems? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-84681@lists.php.net to get a copy of this message | ||
With the latest cvs, if you turn on chargen (port 19 tcp) and run this:
<?
$sock1 = socket_create (AF_INET, SOCK_STREAM, 0);
if($sock1 < 0) die(socket_strerror($sock1));
$res1 = socket_connect($sock1, '127.0.0.1', 19);
if($res1 < 0) die(socket_strerror($sock1));
$sock2 = socket_create (AF_INET, SOCK_STREAM, 0);
if($sock2 < 0) die(socket_strerror($sock1));
$res2 = socket_connect($sock2, '127.0.0.1', 19);
if($res2 < 0) die(socket_strerror($sock1));
$read = array($sock1,$sock2);
while($num=socket_select($read, $write=NULL, $except=NULL, NULL)) {
for($i=0; $i<$num; $i++) {
$msg = socket_read($read[$i],1024);
echo "[$i] ".strlen($msg)."\n";
}
}
?>
I am seeing that every now and then when I run it the output is:
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
[0] 1024
Sometimes it does work properly and it hops back and forth between the two
spewing sockets:
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
[0] 1024
[1] 1024
I would expect to always see it alternate between the two like this. Can
anybody reproduce/explain this?
-Rasmus