/** * 运行守护进程,归档日志文件。 * * @see ZtChart_Model_Monitor_Abstract::run() */ public function run() { sleep($this->_console->getDelayTimestamp()); while (true) { $this->_timestamp = $timestamp = time(); $deadlineTimestamp = $timestamp - self::CYCLE_TIMESTAMP; $this->import($this->_console->getLogPaths(), $deadlineTimestamp); $storage = new ZtChart_Model_Storage('monitor', 'archive'); $storage->write($deadlineTimestamp); time_sleep_until($timestamp + self::CYCLE_TIMESTAMP); } }
/** * 设置根目录 * * @static * @param string $rootDir * @return void */ public static function setRootDirectory($rootDir) { if (!is_readable($rootDir) || !is_writable($rootDir)) { throw new ZtChart_Model_Storage_Exception('The root directory cannot be access.'); } self::$_rootDir = $rootDir; }
/** * 运行守护进程,归档日志文件。 * * @see ZtChart_Model_Monitor_Abstract::run() */ public function run() { if (!is_numeric($startTimestamp = $this->_console->getStartTimestamp())) { if (false === ($startTimestamp = strtotime($startTimestamp))) { throw new ZtChart_Model_Monitor_Daemon_Exception('Start datetime format error.'); } } $this->_timestamp = $startTimestamp; while (true) { if (date($this->_pattern) == date($this->_pattern, $this->_timestamp) || date($this->_pattern, $this->_console->getEndTimestamp()) == date($this->_pattern, $this->_timestamp)) { break; } $this->import($this->_console->getLogPaths(), $this->_timestamp); $storage = new ZtChart_Model_Storage('monitor', 'backup'); $storage->write($this->_timestamp); $this->_timestamp += self::CYCLE_TIMESTAMP; } }
/** * 初始化数据文件存储目录 */ protected function _initStorage() { ZtChart_Model_Storage::setRootDirectory(realpath(__DIR__ . '/../storage')); }