本文整理匯總了PHP中Curl\Curl::progress方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::progress方法的具體用法?PHP Curl::progress怎麽用?PHP Curl::progress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Curl\Curl
的用法示例。
在下文中一共展示了Curl::progress方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Curl
<?php
require __DIR__ . '/vendor/autoload.php';
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://secure.php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
示例2: Curl
<?php
require '../src/Curl/Curl.php';
use Curl\Curl;
$curl = new Curl();
$curl->progress(function ($client, $download_size, $downloaded, $upload_size, $uploaded) {
if ($download_size === 0) {
return;
}
// Display a progress bar: xxx% [=======> ]
$progress_size = 40;
$fraction_downloaded = $downloaded / $download_size;
$dots = round($fraction_downloaded * $progress_size);
printf('%3.0f%% [', $fraction_downloaded * 100);
$i = 0;
for (; $i < $dots - 1; $i++) {
echo '=';
}
echo '>';
for (; $i < $progress_size - 1; $i++) {
echo ' ';
}
echo ']' . "\r";
});
$curl->complete(function ($instance) {
echo "\n" . 'download complete' . "\n";
});
$curl->download('https://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');