首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
onWorkerStart
### 问题描述 ### Swoole4.5.2,PHP7.4.6,centos7.6 ### 相关代码 ```php //server.php <?php class Reload { private $_serv; private $_test; /** * init */ public function __construct() { $this->_serv = new \Swoole\Server("0.0.0.0", 9501); $this->_serv->set([ 'worker_num' => 2, 'daemonize' => true, 'log_file' => __DIR__.'/swoole-task.log', ]); $this->_serv->on('Receive', [$this, 'onReceive']); $this->_serv->on('WorkerStart', [$this, 'onWorkerStart']); } /** * start server */ public function start() { $this->_serv->start(); } public function onWorkerStart($serv, $workerId) { require_once(__DIR__."/crontabDeal.php"); $this->_test = new crontabDeal(); } public function onReceive($serv, $fd, $fromId, $data) { print_r($this->_test->run()); } } $reload = new Reload; $reload->start(); ``` //crontabDeal.php class crontabDeal { public function run() { echo 1; } } ### 你期待的结果是什么?实际看到的错误信息又是什么? 启用后 请求日志输出1,在修改 crontabDeal run 方法 echo 2; 找到进程号 `ps -aux | grep php` 使用命令 ` kill -10` 日志输出 `[2020-06-15 16:32:23 $24602.0] INFO Server is reloading all workers now` 没有更新成功,使用`reload()`也是这样。
发布于6年前 · 2 次浏览 · 来自
提问
拍皇片
### 问题描述 ### Swoole4.5.2,PHP7.4.6,centos7.6 ### 相关代码 ```php //server.php <?php class Reload { private $_serv; private $_test; /** * init */ public function __construct() { $this->_serv = new \Swoole\Server("0.0.0.0", 9501); $this->_serv->set([ 'worker_num' => 2, 'daemonize' => true, 'log_file' => __DIR__.'/swoole-task.log', ]); $this->_serv->on('Receive', [$this, 'onReceive']); $this->_serv->on('WorkerStart', [$this, 'onWorkerStart']); } /** * start server */ public function start() { $this->_serv->start(); } public function onWorkerStart($serv, $workerId) { require_once(__DIR__."/crontabDeal.php"); $this->_test = new crontabDeal(); } public function onReceive($serv, $fd, $fromId, $data) { print_r($this->_test->run()); } } $reload = new Reload; $reload->start(); ``` //crontabDeal.php class crontabDeal { public function run() { echo 1; } } ### 你期待的结果是什么?实际看到的错误信息又是什么? 启用后 请求日志输出1,在修改 crontabDeal run 方法 echo 2; 找到进程号 `ps -aux | grep php` 使用命令 ` kill -10` 日志输出 `[2020-06-15 16:32:23 $24602.0] INFO Server is reloading all workers now` 没有更新成功,使用`reload()`也是这样。
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-06-16
拍皇片
找到原因了 opcache 默认开启了 清空opcache一下就好了
赞
1
回复
2020-06-16
鲁飞
我这里正常。 你用下面这个再试试。 ``` kill -USR1 master进程pid ```
赞
0
回复
2020-06-16
拍皇片
回复
鲁飞
试了好几次就是不行。又换了一个 centos 主机还是这样
赞
0
回复
2020-06-28
卡大大
opcache_reset();//php代码能够重新编译
赞
0
回复