Artisan 进度条 自定义输出格式
自定义输出格式
ProgressBar::setFormatDefinition('minimal', '执行进度: %percent%%');
$progressBar = new ProgressBar($this->output, 3);
$progressBar->setFormat('minimal');
for($i=0;$i<3;$i++){
$progressBar->advance();
sleep(1);
}
显示百分比、内存使用情况、任务剩余时间、估计时间等
$progress = $this->output->createProgressBar(10);
$progress->setFormat('%percent%%');
for ($i=1;$i<10;$i++){
$progress->advance();
sleep(1);
}
$progress->setFormat('%percent%%'); 可以替换为你需要的操作
current
:当前步骤;max
: 最大步数(如果没有定义最大值,则为 0);bar
:进度条本身;percent
:完成百分比(如果没有定义最大值,则不可用);elapsed
: 从进度条开始经过的时间;remaining
:完成任务的剩余时间(如果没有定义max,则不可用);estimated
:完成任务的估计时间(如果没有定义最大值,则不可用);memory
:当前内存使用情况;message
: 用于在进度条中显示任意消息。
重绘屏幕时间调整
出于性能原因,Symfony 每 100 毫秒重绘一次屏幕。如果应用程序来说太快或太慢,可以调整
$progressBar = new ProgressBar($output, 50000);
$progressBar->start();
$progressBar->setRedrawFrequency(100);
$progressBar->maxSecondsBetweenRedraws(0.2);
$progressBar->minSecondsBetweenRedraws(0.1);
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: