Пример #1
0
 protected function logRequest($requestInfo)
 {
     // Get profiling info.
     $profiling = $requestInfo['profiling'];
     $receiveTime = $processTime = $sendTime = 0;
     if (isset($profiling['receive.start']) and isset($profiling['receive.end'])) {
         $receiveTime = ($profiling['receive.end'] - $profiling['receive.start']) * 1000.0;
     }
     if (isset($profiling['process.start']) and isset($profiling['process.end'])) {
         $processTime = ($profiling['process.end'] - $profiling['process.start']) * 1000.0;
     }
     if (isset($profiling['send.start']) and isset($profiling['send.end'])) {
         $sendTime = ($profiling['send.end'] - $profiling['send.start']) * 1000.0;
     }
     $totalTime = ceil($receiveTime + $processTime + $sendTime);
     // Do the logging.
     $request = $requestInfo['request'];
     $response = $requestInfo['response'];
     if ($request and $response) {
         $clientInfo = $this->handler->getClientInfo($requestInfo['socket']);
         $statusName = StupidHttp_WebServer::getHttpStatusHeader($response->getStatus());
         $replacements = array('%date%' => date(self::REQUEST_DATE_FORMAT), '%client_ip%' => $clientInfo['address'], '%client_port%' => $clientInfo['port'], '%method%' => $request->getMethod(), '%uri%' => $request->getUri(), '%path%' => $request->getUriPath(), '%status%' => $response->getStatus(), '%status_name%' => $statusName, '%time%' => $totalTime);
         $this->log->info(str_replace(array_keys($replacements), array_values($replacements), self::REQUEST_LOG_FORMAT));
     }
 }
 /**
  * Builds a new instance of StupidHttp_SocketNetworkHandler.
  */
 public function __construct($address, $port)
 {
     parent::__construct($address, $port);
     $this->sock = null;
     $this->leftOver = null;
 }