我本地新安裝的webman,啟動(dòng)后熱更新過一會(huì)兒就不能用了(修改代碼不生效)
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
奇怪的是當(dāng)使用 php start.php start 啟動(dòng)后,最開始的幾次修改都會(huì)觸發(fā)Workerman[start.php] reloading,但是過一會(huì)兒$this->ppid就會(huì)=0,修改代碼以后不再觸發(fā)Workerman[start.php] reloading,訪問接口響應(yīng)是正常(響應(yīng)修改前的內(nèi)容),沒有報(bào)錯(cuò).
我嘗試再使用 php start.php start 啟動(dòng)后出現(xiàn)$this->ppid=0以后,再新終端執(zhí)行ps -ef | grep webman,發(fā)現(xiàn)
501 7337 98840 0 6:42PM ttys000 0:00.05 WorkerMan: master process start_file=/Users/lijian/Project/webman/start.php
說明主進(jìn)程是正常的,不知為何app/process/Monitor.php中的$this->ppid會(huì)=0,請(qǐng)各位大佬指點(diǎn)一下
macos M4pro芯片+ "workerman/webman-framework": "^2.1.2",
我在控制器中寫了如下代碼監(jiān)控ppid
echo "PID: " . posix_getpid() . ", PPID: " . posix_getppid() . "\n";
當(dāng)修改代碼后提示$this->ppid=0時(shí),我請(qǐng)求接口,控制臺(tái)輸出如下:
PID: 10945, PPID: 10943
在執(zhí)行檢查內(nèi)存的定時(shí)器時(shí)
Timer::add(60, [$this, 'checkMemory'], [$memoryLimit]);
最后定位問題在getMasterPid這個(gè)方法
/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;
}