Skip to content
Permalink
Browse files

Refactoring header sending in Response to remove annoying exception

Also add a fastcgi fast shutdown function in order to squeeze a few
more requests from the webserver
  • Loading branch information...
lorenzo committed Sep 13, 2014
1 parent 6f0347f commit 07e1b6773ceaee3a368ba0f88feee87b080658cf
Showing with 29 additions and 15 deletions.
  1. +29 −15 src/Network/Response.php
@@ -416,23 +416,43 @@ public function send() {
$this->statusCode(302);
}
$codeMessage = $this->_statusCodes[$this->_status];
$this->_setCookies();
$this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}");
$this->_setContent();
$this->_setContentLength();
$this->_setContentType();
foreach ($this->_headers as $header => $values) {
foreach ((array)$values as $value) {
$this->_sendHeader($header, $value);
}
}
$this->sendHeaders();
if ($this->_file) {
$this->_sendFile($this->_file, $this->_fileRange);
$this->_file = $this->_fileRange = null;
} else {
$this->_sendContent($this->_body);
}
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
}
/**
* Sends the HTTP headers and cookies.
*
* @return void
*/
public function sendHeaders() {
if (headers_sent()) {
return;
}
$this->_setCookies();
$codeMessage = $this->_statusCodes[$this->_status];
$this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}");
$this->_setContentType();
foreach ($this->_headers as $header => $values) {
foreach ((array)$values as $value) {
$this->_sendHeader($header, $value);
}
}
}
/**
@@ -519,14 +539,8 @@ protected function _setContentLength() {
* @param string $name the header name
* @param string $value the header value
* @return void
* @throws \RuntimeException When headers have already been sent
*/
protected function _sendHeader($name, $value = null) {
if (headers_sent($filename, $linenum)) {
throw new RuntimeException(
sprintf('Headers already sent in %d on line %s', $linenum, $filename)
);
}
if ($value === null) {
header($name);
} else {

0 comments on commit 07e1b67

Please sign in to comment.
You can’t perform that action at this time.