/** * Forks and exits the CLI process if debugging mode is enabled * * @return void */ private function ___daemoniseIfRequired() { // If debugging is enabled, do not fork, just init the CLI (current process) as MASTER if ($this->_config['Daemon']['daemonize'] == false) { $this->_log("Debug mode enabled thus not forking, just silently initializing as master"); $this->___parent->__registerMe_asMaster(); $this->_pid = getmypid(); return; } // Fork and exit the CLI process to daemonise $pid = pcntl_fork(); if ($pid == -1) { $this->_error('Could not fork'); } if ($pid) { // This is the CLI process $this->_debug("Saying goodbye to pid {$pid} and exiting..."); exit; } // Here is the child which is a daemon now - master process // Register as ma master process $this->___parent->__registerMe_asMaster(); $this->_pid = getmypid(); }