首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
无法获取进程信号
```php <?php $workerNum = 2; $pool = new Swoole\Process\Pool($workerNum); $pool->on("WorkerStart", function ($pool, $workerId) { $running = true; pcntl_signal(SIGTERM, function () use (&$running) { var_dump(3333); $running = false; }); echo "Worker#{$workerId} is started\n"; while ($running) { // var_dump(pcntl_signal_dispatch(),$running); var_dump("aaa\n"); } }); $pool->on("WorkerStop", function ($pool, $workerId) { echo "Worker#{$workerId} is stopped\n"; }); $pool->start(); ``` 版本 swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.16 Built => Mar 5 2020 09:36:22 coroutine => enabled kqueue => enabled rwlock => enabled pcre => enabled zlib => 1.2.8 brotli => E16777223/D16777223 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 => On => On
发布于6年前 · 0 次浏览 · 来自
提问
hahha
```php <?php $workerNum = 2; $pool = new Swoole\Process\Pool($workerNum); $pool->on("WorkerStart", function ($pool, $workerId) { $running = true; pcntl_signal(SIGTERM, function () use (&$running) { var_dump(3333); $running = false; }); echo "Worker#{$workerId} is started\n"; while ($running) { // var_dump(pcntl_signal_dispatch(),$running); var_dump("aaa\n"); } }); $pool->on("WorkerStop", function ($pool, $workerId) { echo "Worker#{$workerId} is stopped\n"; }); $pool->start(); ``` 版本 swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.16 Built => Mar 5 2020 09:36:22 coroutine => enabled kqueue => enabled rwlock => enabled pcre => enabled zlib => 1.2.8 brotli => E16777223/D16777223 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 => On => On
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-03-14
Twosee
你需要使用Event::wait 在 v4.4.0 版本中如果进程的 EventLoop 中只有信号监听的事件,没有其他事件 (例如 Timer 定时器等),进程会直接退出。 pcntl的话用法参考pcntl的文档, 和Swoole没有关系
赞
2
回复
2020-03-14
鲁飞
工作进程为同步模式,请使用 pcntl_signal 和 pcntl_signal_dispatch 监听信号 参考文档[信号处理](https://wiki.swoole.com/#/process_pool?id=start)
赞
1
回复
2020-03-14
Pear
$pool->on("WorkerStart", function ($pool, $workerId) { $running = true; pcntl_signal(SIGTERM, function () use (&$running) { echo "catched\n"; $running = false; }); echo "Worker#{$workerId} is started\n"; $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); $key = "key1"; while ($running) { $msg = $redis->rpop($key); pcntl_signal_dispatch(); if ( $msg == null) continue; var_dump($msg); } });
赞
0
回复
2020-03-14
么么哒
swoole还有社区了
赞
0
回复