From 55214cddb5cbd2dcb29a95dd270bd6d1476ef66d Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 3 Mar 2015 00:59:59 +0700 Subject: [PATCH] Simplify progress example --- examples/progress.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/examples/progress.php b/examples/progress.php index 27e6aa3..8fe42d7 100644 --- a/examples/progress.php +++ b/examples/progress.php @@ -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');