Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CURL progress function callback when downloading/uploading. #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@ Delete an empty bucket:
S3::deleteBucket($bucketName)
```

### Progress Function

Add a progress function when S3 downloading / uploading

```php
S3::setProgressFunction('progress');

function progress($resource,$download_size, $downloaded, $upload_size, $uploaded)
{
if($download_size > 0)
echo $downloaded / $download_size * 100;
ob_flush();
flush();
sleep(1); // just to see effect
}
```
26 changes: 26 additions & 0 deletions S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ class S3
*/
private static $__signingKeyResource = false;

/**
* CURL progress function callback
*
* @var function
* @access public
* @static
*/
public static $progressFunction = null;


/**
* Constructor - if you're not using the class statically
Expand Down Expand Up @@ -355,6 +364,17 @@ public static function freeSigningKey()
openssl_free_key(self::$__signingKeyResource);
}

/**
* Set progress function
*
* @param function $func Progress function
* @return void
*/
public static function setProgressFunction($func = null)
{
self::$progressFunction = $func;
}


/**
* Internal error handler
Expand Down Expand Up @@ -2237,6 +2257,12 @@ public function getResponse()
default: break;
}

// set curl progress function callback
if (S3::$progressFunction) {
curl_setopt($curl, CURLOPT_NOPROGRESS, false);
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, S3::$progressFunction);
}

// Execute, grab errors
if (curl_exec($curl))
$this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
Expand Down