register_streaming_read_callback ( $callback )

Register a callback function to execute whenever a data stream is read from using CFRequest::streaming_read_callback().

The user-defined callback function should accept three arguments:

  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • $file_handle - resource - Required - The file handle resource that represents the file on the local file system.
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.

Access

public

Parameters

Parameter

Type

Required

Description

$callback

string
array
function

Required

The callback function is called by call_user_func(), so you can pass the following values:

  • The name of a global function to execute, passed as a string.
  • A method to execute, passed as array('ClassName', 'MethodName').
  • An anonymous function (PHP 5.3+).

Returns

Type

Description

$this

A reference to the current instance.

Examples

Register a callback function to execute when data is read from an open stream.

$s3 = new AmazonS3();

// Define callback function
function callback($curl_handle, $file_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 read locally.
$s3->register_streaming_read_callback('callback');

// Download a public object.
$response = $s3->create_object('my-bucket', 'my-large-file.mp4', array(
	'fileUpload' => './uploads/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

public function register_streaming_read_callback($callback)
{
    $this->registered_streaming_read_callback = $callback;
    return $this;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback