我有一个守护程序脚本,我试图通过避免线程来保持简单。
当我按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);
}
}