本文整理汇总了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');