Home
Download
Document
Forum
Video
Donate
Source Code
AI 助理
Sponsors
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
Products
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
Login
Register
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
关于process的消息队列中的问提
{{{ <?php $workers = []; $worker_num = 2; for($i = 0; $i < $worker_num; $i++) { $process = new swoole_process('callback_function', false, false); $process->useQueue(); $pid = $process->start(); $workers[$pid] = $process; //echo "Master: new worker, PID=".$pid."\n"; } function callback_function(swoole_process $worker) { //echo "Worker: start. PID=".$worker->pid."\n"; //recv data from master $recv = $worker->pop(); echo "From Master: $recv\n"; $worker->push(" \n hehe \n "); sleep(2); $worker->exit(0); } foreach($workers as $pid => $process) { $process->push("hello worker[$pid]\n"); $result = $process->pop(); echo "From worker: $result\n"; } for($i = 0; $i < $worker_num; $i++) { $ret = swoole_process::wait(); $pid = $ret['pid']; unset($workers[$pid]); echo "Worker Exit, PID=".$pid.PHP_EOL; } }}} 这上面的代码我是根据官网的demo稍微改了一下, 运行结果如下 {{{ From Master: hello worker[3161] From worker: hehe From Master: hello worker[3162] From worker: hehe Worker Exit, PID=3161 Worker Exit, PID=3162 }}} 这个一切正常,但是当 仅仅去掉了 sleep {{{ From Master: hello worker[3190] From worker: hehe PHP Warning: swoole_process::push(): msgsnd() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 29 PHP Warning: swoole_process::pop(): msgrcv() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 30 From worker: PHP Warning: swoole_process::pop(): msgrcv() failed. Error: Identifier removed[43] in /home/sun/learn/swoole/process/demo.php on line 18 From Master: PHP Warning: swoole_process::push(): msgsnd() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 20 Worker Exit, PID=3191 Worker Exit, PID=3190 }}} 我不理解,请问这个代码的运行流程没问题啊,为什么push会失败呢? 或者请给我一个使用消息队列在swoole_process中通讯的例子(swoole_src里的是单向的,没有子进程向主进程发送)
发布于8年前 · 0 次浏览 · 来自
提问
Z
Zevo
{{{ <?php $workers = []; $worker_num = 2; for($i = 0; $i < $worker_num; $i++) { $process = new swoole_process('callback_function', false, false); $process->useQueue(); $pid = $process->start(); $workers[$pid] = $process; //echo "Master: new worker, PID=".$pid."\n"; } function callback_function(swoole_process $worker) { //echo "Worker: start. PID=".$worker->pid."\n"; //recv data from master $recv = $worker->pop(); echo "From Master: $recv\n"; $worker->push(" \n hehe \n "); sleep(2); $worker->exit(0); } foreach($workers as $pid => $process) { $process->push("hello worker[$pid]\n"); $result = $process->pop(); echo "From worker: $result\n"; } for($i = 0; $i < $worker_num; $i++) { $ret = swoole_process::wait(); $pid = $ret['pid']; unset($workers[$pid]); echo "Worker Exit, PID=".$pid.PHP_EOL; } }}} 这上面的代码我是根据官网的demo稍微改了一下, 运行结果如下 {{{ From Master: hello worker[3161] From worker: hehe From Master: hello worker[3162] From worker: hehe Worker Exit, PID=3161 Worker Exit, PID=3162 }}} 这个一切正常,但是当 仅仅去掉了 sleep {{{ From Master: hello worker[3190] From worker: hehe PHP Warning: swoole_process::push(): msgsnd() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 29 PHP Warning: swoole_process::pop(): msgrcv() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 30 From worker: PHP Warning: swoole_process::pop(): msgrcv() failed. Error: Identifier removed[43] in /home/sun/learn/swoole/process/demo.php on line 18 From Master: PHP Warning: swoole_process::push(): msgsnd() failed. Error: Invalid argument[22] in /home/sun/learn/swoole/process/demo.php on line 20 Worker Exit, PID=3191 Worker Exit, PID=3190 }}} 我不理解,请问这个代码的运行流程没问题啊,为什么push会失败呢? 或者请给我一个使用消息队列在swoole_process中通讯的例子(swoole_src里的是单向的,没有子进程向主进程发送)
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2016-12-24
????
这是一个已知BUG,子进程在退出时消息队列被销毁了,所以会报此错误。请使用最新的1.7.19-rc2版本。
赞
0
回复
2019-09-12
l
lmaster
function callback_function(swoole_process $worker) { //echo "Worker: start. PID=".$worker->pid."\n"; //recv data from master $recv = $worker->pop(); echo "From Master: $recv\n"; $worker->push(&quo
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- 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一直是同一个。没用使用到多进程啊。