Php calls stream_get_contents to get data from tcp sockets. Sometimes it can be called all at once, and sometimes if it is empty, a circular query is required.

$socket = stream_socket_server ("tcp://127.0.0.1:8888",$errno,$errstr,STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
if (! $socket) {

die("failed to create a socket");

}
stream_set_blocking ($socket,false);
/ / listen for new connections
$ev = new EvIo ($socket,Ev::READ,function ($watcher) use ($socket,$clients) {

$client = stream_socket_accept($socket);
stream_set_blocking($client,false);
//
$e = new EvIo($client,Ev::READ|Ev::WRITE,function ($watcher) use($client){
    $data = stream_get_contents($client);
    echo $data;//
    /* do{
        $data = stream_get_contents($client);
    }while($data==false);
    ,
    */
    fclose($client);
    $watcher->stop();
});
Ev::run();

});
Ev::run ();

excuse me, what is the cause

Mar.22,2021

you need to know that TCP is streaming protocol , there is no message boundary, UDP has message boundary, so the data from your sender to the receiver may need to receive
610439-20160528150523303-1600111497.png
you can imagine that you are receiving water, so you do not know where
you can search TCP sticky packet problem , and the general solutions are:

  • send a fixed-length packet. If the size of each message is the same, then the receiving peer only needs to accumulate the received data until it is equal to a fixed-length value and treat it as a message.
  • The
  • is tagged with rn at the end of the package. This is exactly what the FTP protocol does. But the problem is that if the data body also contains rn, it will be misjudged as the boundary of the message.
  • header plus packet length. The packet header is a fixed length of 4 bytes, indicating the length of the packet body. The receiving peer first receives the packet length and receives the packet according to the packet length.
  • uses more complex application layer protocols.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39d3b-2c1a8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39d3b-2c1a8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?