我本地新安装的webman,启动后热更新过一会儿就不能用了(修改代码不生效)
Press Ctrl+C to stop. Start success.
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------7337
Workerman[start.php] reloading
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------0
/Users/lijian/Project/webman/app/controller/IndexController.php updated and reload---------0
其中7337是文件app/process/Monitor.php中的$this->ppid
奇怪的是当使用 php start.php start 启动后,最开始的几次修改都会触发Workerman[start.php] reloading,但是过一会儿$this->ppid就会=0,修改代码以后不再触发Workerman[start.php] reloading,访问接口响应是正常(响应修改前的内容),没有报错.
我尝试再使用 php start.php start 启动后出现$this->ppid=0以后,再新终端执行ps -ef | grep webman,发现
501 7337 98840 0 6:42PM ttys000 0:00.05 WorkerMan: master process start_file=/Users/lijian/Project/webman/start.php
说明主进程是正常的,不知为何app/process/Monitor.php中的$this->ppid会=0,请各位大佬指点一下
macos M4pro芯片+ "workerman/webman-framework": "^2.1.2",
我在控制器中写了如下代码监控ppid
echo "PID: " . posix_getpid() . ", PPID: " . posix_getppid() . "\n";
当修改代码后提示$this->ppid=0时,我请求接口,控制台输出如下:
PID: 10945, PPID: 10943
在执行检查内存的定时器时
Timer::add(60, [$this, 'checkMemory'], [$memoryLimit]);
最后定位问题在getMasterPid这个方法
/proc/*是linux下的路径,macos不支持
public function getMasterPid(): int
{
if ($this->ppid === 0) {
return 0;
}
$cmdline = "/proc/$this->ppid/cmdline";
if (!is_readable($cmdline) || !($content = file_get_contents($cmdline)) || (!str_contains($content, 'WorkerMan') && !str_contains($content, 'php'))) {
// Process not exist
echo "MasterPid: $this->ppid not exist\n";
$this->ppid = 0;
}
return $this->ppid;
}
修改
public function getMasterPid(): int
{
$pid_path = config('server.pid_file');
$this->ppid = file_get_contents($pid_path);
if (intval($this->ppid) === 0) {
return 0;
}
return $this->ppid;
}