/** * Initial start command from the terminal. */ public function executeStart() { $logfile = Configuration::get('daemon.log'); Logger::setLog($logfile); if (!empty($mypid) && $mypid != posix_getpid()) { $this->out('Already running.', true); return; } $this->out('Starting Daemon'); $this->startTime = time(); // Get the timezone offset. $date = new DateTime(); $this->timezoneOffset = $date->getOffset(); $this->maxThreads = Configuration::get('daemon.max_threads'); $this->jobs = Configuration::get('jobs'); // If this is not in debug mode, fork to a daemon process. if (!$this->debug) { $this->stdOUT = false; // Create initial fork. $pid = pcntl_fork(); if ($pid == -1) { $this->out('Could not fork.'); return; } else { if ($pid) { // This is the parent thread. $status = null; pcntl_waitpid($pid, $status, WNOHANG); return; } } // This is the child thread. pcntl_signal(SIGCHLD, array($this, 'handlerSIGCHLD')); pcntl_signal(SIGTERM, array($this, 'handlerSIGTERM')); } // Loop infinitely, checking for jobs. $this->lastCheck = time(); do { $this->checkForJobs(); sleep(10); gc_collect_cycles(); } while ($this->keepAlive); }
/** * Create the object and set the logger. */ public function __construct() { Logger::setLog(Configuration::get('cli.log')); }