当前位置:网站首页>Stream in PHP socket communication_ Understanding of select method
Stream in PHP socket communication_ Understanding of select method
2022-06-25 23:47:00 【ndrandy】
About php stream_select Research understanding of methods
function stream_select (array &$read, array &$write, array &$except, $tv_sec, $tv_usec = null) {
}stream_select The condition returned by the function is :
- $read A readable event occurs on any connection in the array
- $write A writable event occurs on any connection in the array
- $except Any connection in the array has out of band data (OOB)
- The current process received a system signal (signal), Such as :pcntl_alarm Generated alarm signal , That is to say, the signal can be interrupted stream_select Call to , Make it return immediately
- stream_select The waiting time for blocking is longer than ($tv_sec+$tv_usec) The total time of , If $tv_sec=&null when , Then unlimited blocking up to the top 4 Any of the return conditions has occurred
Return value
- The return value is the number of connections whose status has changed in all the monitored connections , For example, when there is 3 Writeable events occurred on connections , Cause method to return , The return value is 3(integer type )
- If it is interrupted by the system signal, the return value is false And output a warning ( Interrupted by signal ).
- If nothing happens after waiting until the timeout , Then return to 0
About out of band data
- The out of band data length only supports 1 Characters , For emergency data , For example, pause such functions , An emergency character is sent to the opposite end first , Further emergency treatment
stream_select How to determine whether the connection is readable or writable
- every last socket Each connection has a read buffer (readBuffer) And a write buffer (writeBuffer). Each buffer has a low water mark . Receive buffer low watermark ( Used to judge readable ) And send buffer low watermark ( Used to judge whether it is writable )stream_select The bottom layer traverses all to be monitored socket Connect , And determine the readability and Writeability of each connection in the following way :
- Can be read : When readBuffer The amount of data in ” Equal to ” When receiving the low water mark value . By default, the low water mark value is received =1; There is another case where a readable event occurs , When the opposite end closes the connection , You can use !is_resource($fd) || feof($fd)==true Judge that the connection has been disconnected
- Can write : When writeBuffer Free space remaining in ” Equal to ” When sending the low watermark value , Send low watermark value by default =2048
边栏推荐
猜你喜欢

为什么Integer的比较最好使用equals

Hibernate entity class curd, transaction operation summary

mysql版本升级+数据迁移

Uniapp -- the use of document collation and push of unipush

The simplest screen recording to GIF gadget in history, licecap, can be tried if the requirements are not high

中序线索二叉树

录屏转gif的好用小工具ScreenToGif,免费又好用!

二进制、16进制、大端小端

UE4 learning records create a role and control its movement

Extraction system apk
随机推荐
请问可以不部署服务端实现图片上传吗?
mongodb
Wireshark对IMAP抓包分析
Qtcreator formatting code
UE4 learning record 2 adding skeleton, skin and motion animation to characters
The software test interview has been suspended. The interviewer always says that the logical thinking is chaotic. What should I do?
期末复习【机器学习】
Analysis and comprehensive summary of full type equivalent judgment in go
ACM. Hj16 shopping list ●●
Hibernate entity class curd, transaction operation summary
Ad20 learning notes II
二进制、16进制、大端小端
流数据
7.常用指令(下)v-on,v-bind,v-model的常见操作
森林的先序和中序遍历
为什么Integer的比较最好使用equals
解析产品开发失败的5个根本原因
第五章 习题(124、678、15、19、22)【微机原理】【习题】
1.8 billion pixel Mars panorama Ultra HD released by NASA, very shocking
YUV444、YUV422、YUV420、YUV420P、YUV420SP、YV12、YU12、NV12、NV21