Car*_*uez 7 php command-line-interface symfony progress-bar
我在Symfony2(2.6.6)的简单命令任务中使用了progressbar组件.
我的代码是这样的:
...
$progress = new ProgressBar($output, $total);
$progress->start();
if (($handler = fopen($file, "r")) !== FALSE) {
while (($row = fgetcsv($handler, 1000, ",")) !== FALSE) {
$this->whatever();
$progress->advance();
}
fclose($handler);
$progress->finish();
}
...
Run Code Online (Sandbox Code Playgroud)
输出看起来像:
0/50 [>---------------------------] 0%
5/50 [==>-------------------------] 10%
10/50 [=====>----------------------] 20%
15/50 [========>-------------------] 30%
20/50 [===========>----------------] 40%
25/50 [==============>-------------] 50%
30/50 [================>-----------] 60%
35/50 [===================>--------] 70%
40/50 [======================>-----] 80%
45/50 [=========================>--] 90%
50/50 [============================] 100
Run Code Online (Sandbox Code Playgroud)
进度条不会自动重新加载,每个都显示在一个新行中->advance()
.我确信该函数->whatever();
对输出没有任何作用.
谁知道为什么会这样?谢谢!
对不起我的英语不好
小智 6
您可以setOverwrite()
在初始化进度条时使用:
$progress = new ProgressBar($output, $total);
$progress->setOverwrite(true);
$progress->start();
...
Run Code Online (Sandbox Code Playgroud)
这定义是覆盖进度条还是创建新行。http://api.symfony.com/3.0/Symfony/Component/Console/Helper/ProgressBar.html#method_setOverwrite
归档时间: |
|
查看次数: |
2962 次 |
最近记录: |