register_streaming_write_callback ( $callback )

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

$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 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

public function register_streaming_write_callback($callback)
{
    $this->registered_streaming_write_callback = $callback;
    return $this;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback