【发布时间】:2016-03-08 21:24:24
【问题描述】:
我有一个守护程序脚本,我试图通过避免线程来保持它的简单。
当我 ctrl-c 或 kill 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);? -
我根据一些随机建议将其更改为 100。我假设这只会影响调用处理程序的速度。我已经编辑了我的问题。也许它需要为 1?
-
好吧,哈哈。
-
我回到了我原来的问题,但我会为那个问题提出一个新问题。您想快速回答有关 ticks=1 的问题吗?所以我可以接受它,或者我应该接受吗?