PhpRiot
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

Data Streaming

It is possible to get and put objects using not stream data held in memory but files or PHP streams. This is especially useful when file sizes are large in order not to overcome memory limits.

To receive object using streaming, use method getObjectStream($object, $filename). This method will return Zend_Http_Response_Stream, which can be used as described in HTTP Client Data Streaming section.

Example 774. Zend_Service_Amazon_S3 Data Streaming Example

<?php
$response 
$amazon->getObjectStream("mybycket/zftest");
// copy file
copy($response->getStreamName(), "my/downloads/file");
// use stream
$fp fopen("my/downloads/file2""w");
stream_copy_to_stream($response->getStream(), $fp);


Second parameter for getObjectStream() is optional and specifies target file to write the data. If not specified, temporary file is used, which will be deleted after the response object is destroyed.

To send object using streaming, use putFileStream() which has the same signature as putFile() but will use streaming and not read the file into memory.

Also, you can pass stream resource to putObject() method data parameter, in which case the data will be read from the stream when sending the request to the server.

Zend Framework