/** * update - обновляет конфигурацию системы * * @param mixed $config_file * @static * @access public * @return void */ public static function update($config_file = false) { $config_file = $config_file ?: Config::get('Flags.config'); if (self::load($config_file)) { return Config::set('Flags.config', $config_file); } }
protected static function getLogFileName($name) { $logDir = Config::get('Logger.log_dir'); if (!preg_match("#^\\/#", $logDir)) { $logDir = Config::get('project_root') . "/" . rtrim($logDir, '/'); } return $logDir . '/' . strtolower($name) . '.log'; }
protected static function getPidFileName() { $pidDir = Config::get('Daemon.pid_dir'); if (!preg_match("#^\\/#", $pidDir)) { $pidDir = Config::get('project_root') . "/" . rtrim($pidDir, '/'); } return $pidDir . '/' . static::getName() . '.pid'; }
protected function isItTimeToDie() { return microtime(true) - $this->start_time > Config::get('Daemon.child_ttl'); }
public function deleteChildCollection($name = self::MAIN_COLLECTION_NAME) { if (!empty($name) && !empty($this->child_collections[$name])) { $collection = $this->child_collections[$name]; $collection->stop(); //ждем, пока не остановятся все дочерние процессы static::log('Waiting for all children of "' . $name . '" collection to shutdown...', Logger::L_INFO); static::log('"' . $name . '" collection: ' . $collection->getNumber() . ' of child threads remaining...', Logger::L_INFO); while ($collection->getNumber() > 0) { $this->sigwait(Config::get('Daemon.master_sigwait')); continue; } unset($this->child_collections[$name]); return true; } }
public function sighup() { static::log("Got signal to update config"); if (Config::update()) { Logger::init(); } }
#!/usr/bin/php -q <?php require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php'; require 'Example.php'; use Daemon\Daemon; use Daemon\Utils\Config; // run main cycle Config::set('project_root', __DIR__); Daemon::run(new Master(), 'config.yml');