PHP socket processing does not come over the data flow, how to deal with (as if it is blocked)
Requirements: PHP accepts a hardware to send data to 8888 port, if received, should socket_send function return "\xfa\x01\x01\xff\xaa\xaa\x00\x01\x00\x00\x00\x00\x00\x01", After the hardware receives the data sent by Socket_send, will "drop" a sound, but the problem arises, a hardware is fine, but when more than one hardware connection and send data at the same time, there will be hardware can not be a continuous response (that is, the "drip" sound), that is, to send a continuous "drip" sound, it is not ringing , about a few seconds later, began to respond again, after a while, the hardware on several connections are like this, I have used non-blocking mode, or will do so, to find a solution, the following post code
-
PHP Code
-->= $MAX _users) {$reject = ' Server full.
Try again later.\n ";
///Place the current client connection as Socket_select select $connections [$i] = $newconn;
The input connection resource cache container $writefds [$i] = $newconn;
The connection is not normal if ($reject) {$close [$i] = true;
else {echo "Welcome to the PHP Chat server!\n";
}//initializes the cache container for the current connection read content $input [$i] = "";
Continue
}//Client connection $i = (int) $rfd;
Read $tmp = @socket_read ($RFD, Php_normal_read);
if (! $tmp) {//Read content print "Connection closed on socket $i \ n"; Close ($i);
Continue
$input [$i]. = $tmp;
$tmp = substr ($input [$i],-1);
/*if ($tmp!= "\ r" && $tmp!= "\ n") {/no end of line, more data coming
Continue
}*/$line = Trim ($input [$i]);
$input [$i] = ""; Echo ' Client >> '. $line. "
\ r \ n ";
Socket_getpeername ($connections [$i],& $remoteIP,& $remotePort); echo $remoteIP. "
\ r \ n "; echo $remotePort. "
\ r \ n ";
$data =str_split ($buffer);
Print_r ($data);
$str = "\xfa\x01\x01\xff\xaa\xaa\x00\x01\x00\x00\x00\x00\x00\x01";
Socket_send ($connections [$i], $str, strlen ($STR), 0);
foreach ($writefds as $wfd) {$i = (int) $wfd;
$w = Socket_write ($wfd, "Hello"); }} function CloSE ($i) {Global $connections, $input, $close;
Socket_shutdown ($connections [$i]);
Socket_close ($connections [$i]);
Unset ($connections [$i]);
Unset ($input [$i]);
Unset ($close [$i]);
}?>