ZF-6736: Allow writing the response body into a stream


Currently the response body is stored as a string inside the response object. When it concerns big responses, like file downloads, this can take up quite some memory and you might go over PHP's memory limit.

To avoid such situations it would be nice to be able to write the body (after processing the transfer-encoding, NOT the raw body) directly into a PHP stream / file.


File download should not pass throught the MVC system, but should directly be served by the WebServer (Apache's mod_xsendfile is good for that) Even if the dispatching may end on a file to be served, then it should send a 3xx HTTP response code to make the browser equest for it directly.

Am I wrong or did I miss something ? Perhaps you have a use-case to provide ?

Hi Julien

I think you missed the point, or I lacked in making my issue report clear enough, as I am talking not about MVC but about responses to requests made with Zend_Http_Client.

$client = new Zend_Http_client('http://example.com/somefile'); $response = $client->request();

The full raw HTTP response body is now as a string inside the protected member variable $response->body, using up memory.

Yes yes, all my fault of not reading deeply the subject.

So I agree with your issue, if I can provide some patch, I would ;-)

This doesnt make sense imho, since the raw response is put together in one piece anyways for processing you have the complete response at one point in time no matter what and can reach memory limit with that.

Hi Benjamin, that's exactly my point, that in certain cases you would not want to have the raw response kept in memory but instead written to a stream (a file stream for example) as the data gradually comes in.

Downloading bigger files from Amazon S3 on a limited PHP environment is now impossible exactly because of the current implementation.

I think I know how to make it work.

Solution checked into trunk.