😊 Gateway-woker实现热重载 密级: 【C-1】 | 时间:2024-02-20 | 目录:编程开发 | 编辑本文 文章距今已发表三个月,请自行判断文中技术方法、代码的有效性:) ## 原理 onWorkerStart事件时添加一个计时器,绑定文件监控的代码函数即可。 ## 代码 ```php 'init', 'client_id' => $client_id ))); } // GatewayWorker建议不做任何业务逻辑,onMessage留空即可 public static function onMessage($client_id, $message) { // $data= json_decode($message,true); // $op = $data['op']; // $data = $data['data']; Gateway::sendToClient($client_id, json_encode(array( 'data222' => $message, 'client_id' => $client_id ))); } public static function onWorkerStart($businessWorker) { $last_mtime = time(); $_dir = "/app/app/index/controller"; Timer::add(1, function () use (&$_dir,&$last_mtime) { $dir_iterator = new RecursiveDirectoryIterator($_dir); $iterator = new RecursiveIteratorIterator($dir_iterator); foreach ($iterator as $file) { // only check php files if(pathinfo($file, PATHINFO_EXTENSION) != 'php') { continue; } // check mtime if($last_mtime < $file->getMTime()) { echo $file." update and reload\n"; // send SIGUSR1 signal to master process for reload posix_kill(posix_getppid(), SIGUSR1); $last_mtime = $file->getMTime(); break; } } }); } } ``` ## 效果 ![](https://img.meituan.net/imgupload/0b89a60d131638799279133eb18e6c3f259910.png) ## 吐槽 官方这文档 不忍直视 评论列表 5440e72a 2024/01/29 感谢!!找了很久 depy 发布于 上海 不客气呢 写评论 您的IP:18.226.165.21,临时用户名:26f0ab23评论已接入DepyWAF审计与流量系统,请勿频繁操作导致IP拉黑 提交评论 © 版权声明:非标注『转载』情况下本文为原创文章,版权归 Depy's docs 所有,转载请联系博主获得授权。
感谢!!找了很久
不客气呢