/** * Logs stats for a new response. * * @access private * @param HTTPResponse $response * @return void */ private function _log_response(HTTPResponse $response) { $ip = $this->request->get_remote_ip(); $response->set_default_headers(); // Tally up the total bytes sent. if ($this->request->get_controller_method() == 'websocket') { if (!isset(self::$_ws_bytes_sent[$ip])) { self::$_ws_bytes_sent[$ip] = 0; } self::$_ws_bytes_sent[$ip] += strlen($response->get_body()); } elseif ($this->request->get_controller_method() == 'long_polling') { if (!isset(self::$_lp_bytes_sent[$ip])) { self::$_lp_bytes_sent[$ip] = 0; } self::$_lp_bytes_sent[$ip] += strlen($response); } elseif ($this->request->get_controller_method() == 'short_polling') { if (!isset(self::$_sp_bytes_sent[$ip])) { self::$_sp_bytes_sent[$ip] = 0; } self::$_sp_bytes_sent[$ip] += strlen($response); } }
/** * Logs stats for a new response. * * @access private * @param HTTPResponse $response * @return void */ private function _log_response(HTTPResponse $response) { $response->set_default_headers(); // Tally up the total bytes sent. if ($this->request instanceof WSRequest) { self::$_ws_bytes_sent += strlen($response->get_body()); } else { self::$_lp_bytes_sent += strlen($response); } }
/** * Writes data to the client. If the method returns true, the connection should be * closed. * * @access public * @param HTTPResponse $chunk * @return boolean */ public function write(HTTPResponse $chunk) { $chunk->set_default_headers(); // Check to see if we should close the connection or allow it to stay open. $keepalive = $this->connection->keep_alive(); if ($keepalive) { $chunk->add_header('Connection', 'Keep-Alive'); $chunk->add_header('Keep-Alive', 'timeout=' . $this->connection->config('KEEPALIVE_TIMEOUT') . ', max=' . $this->connection->get_keepalives_left()); } else { $chunk->add_header('Connection', 'close'); } $this->connection->write((string) $chunk); return true; }