diff --git a/util/daemon.php b/util/daemon.php new file mode 100644 index 0000000000..d1eb70d8b1 --- /dev/null +++ b/util/daemon.php @@ -0,0 +1,96 @@ +config['php_path'])) { + $php = $a->config['php_path']; +} else { + $php = "php"; +} + +// Switch over to daemon mode. +if ($pid = pcntl_fork()) + return; // Parent + +fclose(STDIN); // Close all of the standard +fclose(STDOUT); // file descriptors as we +fclose(STDERR); // are running as a daemon. + +register_shutdown_function('shutdown'); + +if (posix_setsid() < 0) + return; + +if ($pid = pcntl_fork()) + return; // Parent + +$pid = getmypid(); +file_put_contents($pidfile, $pid); + +// Now running as a daemon. +while (true) { + // Call the poller + $cmdline = $php.' include/poller.php'; + + exec($cmdline); + + // Now sleep for 5 minutes + sleep(300); +} +?>