Esempio n. 1
0
 /**
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  *
  * @return array
  */
 protected function getLogData(RequestInterface $request, ResponseInterface $response = null)
 {
     $time = $this->stopwatch->stop(self::STOPWATCH_EVENT)->getDuration();
     $uagent = $request->getHeader('User-Agent', '-');
     $uagent = $uagent[0];
     $xcache = $response && $response->hasHeaderWithValue('x-cache', 'HIT') ? 'HIT' : 'MISS';
     $postDumpLimit = 200;
     $postData = json_encode($request->getPostParams());
     if (strlen($postData) > $postDumpLimit) {
         $postData = substr($postData, 0, $postDumpLimit) . '...';
     }
     $data = array();
     $data[] = $xcache;
     $data[] = bcdiv($time, 1000, 4);
     // milliseconds
     $data[] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // @todo ip is always set to 127.0.0.1 due to broken request object
     $data[] = $request->getMethod();
     $data[] = $request->getUri();
     $data[] = $response ? $response->getStatusCode() : '-';
     // bytes
     $data[] = $response ? $response->getLength() : '-';
     // bytes
     $data[] = sprintf('"%s"', $uagent);
     $data[] = $postData;
     return $data;
 }
Esempio n. 2
0
 /**
  * Tell if current response comes from cache
  *
  * @param ResponseInterface $response
  *
  * @return bool
  */
 private function isResponseFromCache(ResponseInterface $response)
 {
     return $response->hasHeaderWithValue('X-Cache', 'HIT');
 }