#!/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.' bin/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); }