public function testUseSimpleLogger() { Logger::useSimpleLogger($this->_logFile); Logger::info('xxinfoxx'); Logger::err('xxerrxx'); Logger::debug('xxdebugxx'); $contents = file_get_contents($this->_logFile); $ms = null; $this->assertEquals(1, preg_match('/xxinfoxx/', $contents, $ms)); $this->assertEquals(1, preg_match('/xxerrxx/', $contents, $ms)); $this->assertEquals(1, preg_match('/xxdebugxx/', $contents, $ms)); Logger::useNullLogger(); Logger::info('bbbb'); $contents1 = file_get_contents($this->_logFile); $this->assertEquals($contents1, $contents); }
protected function dealWithTermTimeout() { if ($this->isDealedWithTermTimeout) { return false; } if (microtime(true) - $this->termTime <= $this->config->getTermTimeout()) { return false; } try { Logger::info("process[" . $this->getProcess()->getPid() . "] will be killed for termTimeout"); $this->getProcess()->kill(); $this->isDealedWithTermTimeout = true; } catch (\Exception $e) { Logger::err($e); return false; } return true; }
/** * @return void */ public function keep() { Logger::debug(__METHOD__ . '()'); $this->_stoped = false; try { while (!$this->_stoped) { if (\count($this->_children) < $this->_config->getQuantity()) { $this->_startOne(); continue; } $status = null; $pid = \pcntl_wait($status, \WNOHANG); if ($pid > 0) { $this->_processExit($pid); continue; } $this->_checkTimeout(); \usleep($this->_checkingInterval); } } catch (StopSignal $ex) { Logger::info('Received a StopSignal'); $this->_waitToEnd(); } }