From 80d221089513ed0301ea5c1cc2241b87d22a0767 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 27 Nov 2016 20:57:18 +0000 Subject: [PATCH] We can now start the poller from a daemon as well. --- util/daemon.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 util/daemon.php 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); +} +?> -- 2.39.5