1
我有一個守護進程腳本,我試圖通過避免線程保持簡單。殺死被「系統」調用吸收,從不觸發pcntl_signal
當我ctrl-c或殺死PID,「系統」調用退出,但不調用exitFunction。
declare(ticks = 100);
function exitFunction($signo) {
global $pidFile, $exit;
unlink($pidFile);
echo "Daemon is exiting (signal: $signo). Removing pidFile: $pidFile\n";
$exit = true;
};
//create the signal handler and shutdown function
pcntl_signal(SIGINT, "exitFunction");
pcntl_signal(SIGTERM, "exitFunction");
//create the pid file with our command
file_put_contents($pidFile, posix_getpid());
echo "pid: " . posix_getpid() . "\n";
echo "Time to start!\n";
while(!$exit) {
echo "running $command...\n";
system($command, $return);
echo "done $command\n";
if($return) {
echo "didn't find any domains with command, so sleeping for 60...\n";
sleep(60);
}
}
您是否在腳本中添加了'declare(ticks = 1);'作爲第一行? – avip
我將它更改爲100,因爲有一些隨機的建議。我假設這只是影響處理程序被調用的速度。我編輯了我的問題。也許它需要1? –
好的工作,哈哈。 –