From: Hypolite Petovan Date: Mon, 19 Mar 2018 03:24:09 +0000 (-0400) Subject: Move scripts/daemon.php to bin/ X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e7e497e244a91f38416bf26015ecb952282b13b0;p=friendica.git Move scripts/daemon.php to bin/ --- diff --git a/bin/daemon.php b/bin/daemon.php new file mode 100644 index 0000000000..b53a69e1b9 --- /dev/null +++ b/bin/daemon.php @@ -0,0 +1,126 @@ +#!/usr/bin/env php +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) { + // Just to be sure that this script really runs endlessly + set_time_limit(0); + + // Call the worker + $cmdline = $php.' scripts/worker.php'; + + $executed = false; + + if (function_exists('proc_open')) { + $resource = proc_open($cmdline . ' &', array(), $foo, $directory); + + if (is_resource($resource)) { + $executed = true; + proc_close($resource); + } + } + + if (!$executed) { + exec($cmdline.' spawn'); + } + + // Now sleep for 5 minutes + sleep(300); +} diff --git a/scripts/daemon.php b/scripts/daemon.php deleted file mode 100755 index a9b8d1d262..0000000000 --- a/scripts/daemon.php +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env php -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) { - // Just to be sure that this script really runs endlessly - set_time_limit(0); - - // Call the worker - $cmdline = $php.' scripts/worker.php'; - - $executed = false; - - if (function_exists('proc_open')) { - $resource = proc_open($cmdline . ' &', array(), $foo, $directory); - - if (is_resource($resource)) { - $executed = true; - proc_close($resource); - } - } - - if (!$executed) { - exec($cmdline.' spawn'); - } - - // Now sleep for 5 minutes - sleep(300); -}