Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


Zend_Http_Response provides easy access to an HTTP responses message, as well as a set of static methods for parsing HTTP response messages. Usually, Zend_Http_Response is used as an object returned by a Zend_Http_Client request.

In most cases, a Zend_Http_Response object will be instantiated using the fromString() method, which reads a string containing a HTTP response message, and returns a new Zend_Http_Response object:

Example 502. Instantiating a Zend_Http_Response Object Using the Factory Method

$sock fsockopen(''80);
$req =     "GET / HTTP/1.1\r\n" .
"Host:\r\n" .
"Connection: close\r\n" .

while (
$buff fread($sock1024))
$str .= $sock;

$response Zend_Http_Response::fromString($str);

You can also use the contractor method to create a new response object, by specifying all the parameters of the response:

public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)

  • $code: The HTTP response code (eg. 200, 404, etc.)

  • $headers: An associative array of HTTP response headers (eg. 'Host' => '')

  • $body: The response body as a string

  • $version: The HTTP response version (usually 1.0 or 1.1)

  • $message: The HTTP response message (eg 'OK', 'Internal Server Error'). If not specified, the message will be set according to the response code

Zend Framework