In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the reason why swoole can not use sleep". In daily operation, I believe that many people have doubts about the reason why swoole cannot use sleep. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt that "swoole can not use sleep". Next, please follow the editor to study!
Because in swoole, using the sleep function will cause the process to fall into sleep blocking; only the signal in the sleep process can be interrupted, because the signal of swoole is based on signalfd, so even if the signal is sent, the sleep cannot be interrupted, and only after the specified time will the operating system wake up the current process again.
Operating environment of this tutorial: Windows10 system, Swoole4 version, DELL G3 computer
Why can't swoole use sleep?
Sleep/usleep/time_sleep_until/time_nanosleep must not be used in asynchronous IO programs. (the use of sleep below generally refers to all sleep functions)
The sleep function causes the process to fall into a sleep block
The operating system will not reawaken the current process until the specified time
During sleep, only the signal can interrupt.
Since the signal processing of Swoole is based on signalfd, the sleep cannot be interrupted even if the signal is sent.
Swoole_event_add, swoole_timer_tick, swoole_timer_after, swoole_process::signal, and asynchronous swoole _ client provided by Swoole stop working after the process sleep. Swoole_server can no longer process new requests.
Example program
$serv = new swoole_server ("127.0.0.1", 9501); $serv- > set (['worker_num' = > 1]); $serv- > on (' receive', function ($serv, $fd, $from_id, $data) {sleep (100); $serv- > send ($fd, 'Swoole:'. $data);}); $serv- > start ()
The sleep function is executed in the onReceive event, and server cannot receive any more client requests within 100 seconds.
At this point, the study on "what is the reason why swoole cannot use sleep" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.