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套接字则不会.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...