首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
自定义进程内多个监听信号的协程未被逐个唤醒
### 问题描述 自定义进程内多个监听信号的协程未被逐个唤醒 ### Swoole版本,PHP版本,以及操作系统版本信息 ```bash [root@localhost swooleApi]# php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.8.2 Built => Dec 2 2021 15:54:09 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled curl-native => enabled pcre => enabled c-ares => 1.10.0 zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 [root@localhost swooleApi]# php -v PHP 7.4.25 (cli) (built: Nov 18 2021 13:36:50) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@localhost swooleApi]# uname -a Linux localhost.localdomain 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ``` ### 相关代码 ```php <?php use Swoole\Coroutine; use Swoole\Coroutine\Channel; use Swoole\Runtime; require_once __DIR__.'/vendor/autoload.php'; Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL); $http = new Swoole\Http\Server("127.0.0.1", 7501, SWOOLE_PROCESS); $http->on('start', function (Swoole\Server $server) { file_put_contents(__DIR__ . '/master.pid', (string)$server->master_pid); }); $http->on('request', function ($request, $response) { $response->end('hello'); }); $http->set([ 'max_wait_time' => 3, 'worker_num' => 1, 'reload_async' => false, ]); $http->addProcess(new Swoole\Process(function ($process) use ($http) { $signal = true; $sleep = new Channel(); Swoole\Coroutine::create(function () use(&$signal, $sleep) { defer(function () {var_dump('收到退出信号 1 -->'.date('s'));}); while (true) { $ret = Coroutine\System::waitSignal(SIGTERM,-1); if($ret) { $signal = false; //收到结束信号 $sleep->push(true); break; } } }); Swoole\Coroutine::create(function () { defer(function () {var_dump('收到退出信号 2 -->'.date('s'));}); while (true) { $ret = Coroutine\System::waitSignal(SIGTERM,-1); if($ret) break; } }); while ($signal) { if($sleep->pop(1)) { var_dump('取消sleep -->'.date('s')); break; } //搞事情 } echo 'process stop'.PHP_EOL; }, false, 2, 1)); $http->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 给master进程15信号后,期待打印: ```bash [2022-03-18 11:13:12 #5109.1] INFO Server is shutdown now string(26) "收到退出信号 1 -->12" string(26) "收到退出信号 2 -->12" string(26) "取消sleep --> -->12" ``` 实际打印: ```bash [2022-03-18 11:13:12 #5109.1] INFO Server is shutdown now string(26) "收到退出信号 2 -->12" ```
发布于2年前 · 7 次浏览 · 来自
提问
天王盖地虎
### 问题描述 自定义进程内多个监听信号的协程未被逐个唤醒 ### Swoole版本,PHP版本,以及操作系统版本信息 ```bash [root@localhost swooleApi]# php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.8.2 Built => Dec 2 2021 15:54:09 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled curl-native => enabled pcre => enabled c-ares => 1.10.0 zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 [root@localhost swooleApi]# php -v PHP 7.4.25 (cli) (built: Nov 18 2021 13:36:50) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@localhost swooleApi]# uname -a Linux localhost.localdomain 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ``` ### 相关代码 ```php <?php use Swoole\Coroutine; use Swoole\Coroutine\Channel; use Swoole\Runtime; require_once __DIR__.'/vendor/autoload.php'; Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL); $http = new Swoole\Http\Server("127.0.0.1", 7501, SWOOLE_PROCESS); $http->on('start', function (Swoole\Server $server) { file_put_contents(__DIR__ . '/master.pid', (string)$server->master_pid); }); $http->on('request', function ($request, $response) { $response->end('hello'); }); $http->set([ 'max_wait_time' => 3, 'worker_num' => 1, 'reload_async' => false, ]); $http->addProcess(new Swoole\Process(function ($process) use ($http) { $signal = true; $sleep = new Channel(); Swoole\Coroutine::create(function () use(&$signal, $sleep) { defer(function () {var_dump('收到退出信号 1 -->'.date('s'));}); while (true) { $ret = Coroutine\System::waitSignal(SIGTERM,-1); if($ret) { $signal = false; //收到结束信号 $sleep->push(true); break; } } }); Swoole\Coroutine::create(function () { defer(function () {var_dump('收到退出信号 2 -->'.date('s'));}); while (true) { $ret = Coroutine\System::waitSignal(SIGTERM,-1); if($ret) break; } }); while ($signal) { if($sleep->pop(1)) { var_dump('取消sleep -->'.date('s')); break; } //搞事情 } echo 'process stop'.PHP_EOL; }, false, 2, 1)); $http->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 给master进程15信号后,期待打印: ```bash [2022-03-18 11:13:12 #5109.1] INFO Server is shutdown now string(26) "收到退出信号 1 -->12" string(26) "收到退出信号 2 -->12" string(26) "取消sleep --> -->12" ``` 实际打印: ```bash [2022-03-18 11:13:12 #5109.1] INFO Server is shutdown now string(26) "收到退出信号 2 -->12" ```
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
还没有评论!
微信公众号
热门内容
作者其它话题
- 一个生产者协程通过channel让多个消费者协程消费的代码,内存不断上涨
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。