首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
Swoole\Process\Pool多进程代码热更新问题
以包含文件的方式引入代码,当使用SIGUSR1、SIGUSR2、USR1、USR2进行重启的时候都不能实现代码更新,表现在计算以及写文件的内容。不知道为什么**** swoole.php <?php $workerNum = 10; $pool = new Swoole\Process\Pool($workerNum); $pool->on("WorkerStart", function ($pool, $workerId) { require_once './data_process.php'; $run = new data_process($workerId); $run->run(); }); $pool->on("WorkerStop", function ($pool, $workerId) { echo "Worker#{$workerId} is stopped\n"; }); $pool->start(); <?php class data_process { public $workId = 0; public function __construct($workId = 0) { $this->workId = $workId; } public function run() { echo "Worker#{$this->workId} is started **888**\n"; file_put_contents(dirname(__FILE__).'/a.txt', PHP_EOL.'bb', FILE_APPEND); $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); $key = "key1"; while (true) { $msg = $redis->brpop($key, 2); if ( $msg == null) continue; $msg[1] += 1; var_dump($msg); } return; } }
发布于6年前 · 6 次浏览 · 来自
提问
bredeli
以包含文件的方式引入代码,当使用SIGUSR1、SIGUSR2、USR1、USR2进行重启的时候都不能实现代码更新,表现在计算以及写文件的内容。不知道为什么**** swoole.php <?php $workerNum = 10; $pool = new Swoole\Process\Pool($workerNum); $pool->on("WorkerStart", function ($pool, $workerId) { require_once './data_process.php'; $run = new data_process($workerId); $run->run(); }); $pool->on("WorkerStop", function ($pool, $workerId) { echo "Worker#{$workerId} is stopped\n"; }); $pool->start(); <?php class data_process { public $workId = 0; public function __construct($workId = 0) { $this->workId = $workId; } public function run() { echo "Worker#{$this->workId} is started **888**\n"; file_put_contents(dirname(__FILE__).'/a.txt', PHP_EOL.'bb', FILE_APPEND); $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); $key = "key1"; while (true) { $msg = $redis->brpop($key, 2); if ( $msg == null) continue; $msg[1] += 1; var_dump($msg); } return; } }
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-03-20
郭新华
require once改成require试下,另外opcache扩展卸载掉试下
赞
1
回复
2020-03-20
bredeli
回复
郭新华
卸载zend opcache可以,但是使用opache_reset()这个函数不起作用。不清楚是什么原因 $workerNum = 10; $pool = new Swoole\Process\Pool($workerNum); $pool->on("WorkerStart", function ($pool, $workerId) { var_dump(opcache_reset()); if (function_exists('apc_clear_cache')) { apc_clear_cache(); } require './data_process.php'; $run = new data_process($workerId); $run->run(); }); $pool->on("WorkerStop", function ($pool, $workerId) { var_dump(opcache_reset()); echo "Worker#{$workerId} is stopped\n"; }); $pool->start();
赞
0
回复
2020-03-19
Twosee
可以在onWorkerStart打印下`getmypid()`看看进程是否重启了
赞
0
回复
2020-03-19
bredeli
回复
Twosee
是重启了,进程ID变了,getmypid打印的也变了。可以用我贴的代码测试一下
赞
0
回复
2020-12-04
路上
回复
bredeli
你好请问问题解决了吗 我这边遇到一个小问题 就是进程外实例化了以后 导致子进程的这个类不能热更新 ```php $model = new Finance_TaskerModel(); $workerNum = $model->taskCon['count']??1; $pool = new Swoole\Process\Pool(2); unset($model); $pool->on("WorkerStart", function ($pool, $workerId) { $model1 = new Finance_TaskerModel($workerId); $model1->run($workerId); unset($model1); }); $pool->on("WorkerStop", function ($pool, $workerId) { echo "Worker#{$workerId} is stopped\n"; }); $pool->start(); ```
赞
0
回复