php – 非阻塞套接字:消息是否排队?

前端之家收集整理的这篇文章主要介绍了php – 非阻塞套接字:消息是否排队?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
据我了解,可以在 PHP 5.x中创建 nonblocking网络 socket.

但是如果脚本使用相同的非阻塞套接字发送几条长消息,会发生什么?

socket_write($socket,$string1,$length);
socket_write($socket,$string2,$string3,$string4,$length);

这些消息是否排队(在发送方/接收方?)或者接收方是否可能因为发送“并行”而获取不同消息的一部分?

例如:接收器是否有可能获得10个字节的$string1,然后30个字节的$string2,然后是另外25个字节的$string1 ……等等……

这取决于套接字正在使用的协议.有关可能的插座类型,请参阅 socket_create.主要类型是UDP和TCP:

udp The User Datagram Protocol is a connectionless,unreliable,protocol with fixed record lengths. Due to these aspects,UDP requires a minimum amount of protocol overhead.

tcp The Transmission Control Protocol is a reliable,connection based,stream oriented,full duplex protocol. TCP guarantees that all data packets will be received in the order in which they were sent. If any packet is somehow lost during communication,TCP will automatically retransmit the packet until the destination host acknowledges that packet. For reliability and performance reasons,the TCP implementation itself decides the appropriate octet boundaries of the underlying datagram communication layer. Therefore,TCP applications must allow for the possibility of partial record transmission.

要直接回答您的问题,TCP套接字将保证按顺序传送,而UDP套接字则不会.

原文链接:https://www.f2er.com/php/136269.html

猜你在找的PHP相关文章