Register a callback function to execute whenever a data stream is written to using
CFRequest::streaming_write_callback().
The user-defined callback function should accept two arguments:
$curl_handle-resource- Required - The cURL handle resource that represents the in-progress transfer.$length-integer- Required - The length in kilobytes of the data chunk that was transferred.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
The callback function is called by
|
Returns
Type |
Description |
|---|---|
|
A reference to the current instance. |
Examples
Register a callback function to execute when data is written to an open stream.
$s3 = new AmazonS3();
// Define callback function
function callback($curl_handle, $length)
{
$total = curl_getinfo($curl_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
$transferred = curl_getinfo($curl_handle, CURLINFO_SIZE_DOWNLOAD);
$percentage = floor(($transferred / $total) * 100);
echo 'Transferred ' . $transferred . ' KB out of ' . $total . ' KB (' . $percentage . '%)' . PHP_EOL;
}
// Register a callback function to execute when a stream is written locally.
$s3->register_streaming_write_callback('callback');
// Download a public object.
$response = $s3->get_object('my-bucket', 'my-large-file.mp4', array(
'fileDownload' => './downloads/my-large-file.mp4'
));
Result:
Transferred 7200 bytes out of 9000000 (0%) ... Transferred 9000000 bytes out of 9000000 (100%)
Source
Method defined in sdk.class.php | Toggle source view (5 lines) | View on GitHub

