当前位置:网站首页>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
边栏推荐
- The package name of the manifest file in the library project and the app project are not the same
- InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
- 使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容
- STL教程5-STL基本概念及String和vector使用
- Reproduction of an implant found by Kaspersky that writes shellcode into evenlog
- C. Planar Reflections-CodeCraft-21 and Codeforces Round #711 (Div. 2)
- WordPress
- Leetcode-1528- rearrange string - hash table - string
- 6.常用指令(上)v-cloak,v-once,v-pre
- 谈一谈PHP变量或参数的Copy On Write机制
猜你喜欢
随机推荐
一文讲透研发效能!您关心的问题都在
Jenkins 发布PHP项目代码
A. Balance the Bits--Codeforces Round #712 (Div. 1)
请问可以不部署服务端实现图片上传吗?
String object (constant) pool
mysql集群
Hbuilderx uses the gaude map to obtain the current location
Leetcode (435) - no overlapping interval
OpenJudge NOI 2.1 15:Counterfeit Dollar
Hibernate core api/ configuration file / L1 cache details
Uniapp -- framework arrangement and analysis summary
4个要点,助力产品管好项目
Hibernate architecture introduction and environment construction (very detailed)
Wireshark对IMAP抓包分析
使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容
SVN
音频基础知识以及PCM转WAV
Spark日志分析
Once beego failed to find bee after passing the go get command Exe's pit
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)








