加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:05:33 所属栏目:PHP教程 来源:网络整理
导读:据我了解,可以在 PHP 5.x中创建 nonblocking网络 socket. 但是如果脚本使用相同的非阻塞套接字发送几条长消息,会发生什么? socket_write($socket,$string1,$length);socket_write($socket,$string2,$string3,$string4,$length); 这些消息是否排队(在发送方/
据我了解,可以在 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套接字则不会.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读