mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 20:20:53 +00:00
Simplify progress example
This commit is contained in:
+4
-20
@@ -3,29 +3,13 @@ require '../src/Curl/Curl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
$last_progress = 0;
|
||||
$last_progress_time = 0;
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->progress(function ($client, $download_size, $downloaded, $upload_size, $uploaded){
|
||||
|
||||
global $last_progress;
|
||||
global $last_progress_time;
|
||||
|
||||
if($download_size == 0)
|
||||
if ($download_size === 0) {
|
||||
return;
|
||||
|
||||
$now = time();
|
||||
}
|
||||
|
||||
$progress = floor( $downloaded * 100 / $download_size );
|
||||
|
||||
// print progress every one second
|
||||
if(($now - $last_progress_time) > 1 && $last_progress != $progress)
|
||||
{
|
||||
echo $progress . "%\n";
|
||||
|
||||
$last_progress = $progress;
|
||||
$last_progress_time = $now;
|
||||
}
|
||||
echo ' ' . $progress . '%' . "\r";
|
||||
});
|
||||
$curl->download('http://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
|
||||
$curl->download('https://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
|
||||
|
||||
Reference in New Issue
Block a user