Files
php-curl-class/examples/curl_progress.php
T
2023-06-30 01:23:37 -07:00

25 lines
656 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
// Note: The server needs to send a content-length header for progress to work.
use Curl\Curl;
$curl = new Curl();
$curl->progress(function ($client, $download_size, $downloaded, $upload_size, $uploaded) {
if ($download_size === 0) {
return;
}
$percent = floor($downloaded * 100 / $download_size);
echo ' ' . $percent . '%' . "\r";
});
$curl->download('https://www.php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
if ($curl->error) {
echo 'Download error: ' . $curl->errorMessage . "\n";
} else {
echo 'Download complete' . "\n";
}