Zend_Http_Client accepts and returns data as
PHP strings. However, in many cases there are big files to be sent or
received, thus keeping them in memory might be unnecessary or too expensive. For these
Zend_Http_Client supports reading data from files (and in
general, PHP streams) and writing data to files (streams).
In order to use stream to pass data to
setRawData() method with data argument being stream
resource (e.g., result of
Example 473. Sending file to HTTP server with streaming
$fp = fopen("mybigfile.zip", "r");
Only PUT requests currently support sending streams to HTTP server.
In order to receive data from the server as stream, use
setStream(). Optional argument specifies the filename where the
data will be stored. If the argument is just
temporary file will be used and will be deleted once response object is destroyed.
Setting argument to
FALSE disables the streaming functionality.
When using streaming,
request() method will return object of
Zend_Http_Client_Response_Stream, which has two useful
getStreamName() will return the name of the file where
the response is stored, and
getStream() will return stream from
which the response could be read.
You can either write the response to pre-defined file, or use temporary file for storing it and send it out or write it to another file using regular stream functions.
Example 474. Receiving file from HTTP server with streaming
$client->setStream(); // will use temp file
$response = $client->request('GET');
// copy file
// use stream
$fp = fopen("my/downloads/file2", "w");
// Also can write to known file