laravel 命令行输出进度条
生活随笔
收集整理的這篇文章主要介紹了
laravel 命令行输出进度条
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
有時候我們想在命令行執(zhí)行一些耗時的命令,我們可以利用 symfony 提供的進(jìn)度條相關(guān)的類,來輸出一個進(jìn)度條,顯示當(dāng)前的處理進(jìn)度。
參考:http://symfony.com/doc/current/components/console/helpers/progressbar.html
?
<?phpnamespace App\Commands;use App\Console\Commands\BaseCommand; use Illuminate\Contracts\Bus\SelfHandling; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Output\ConsoleOutput;class Test extends BaseCommand implements SelfHandling {protected $signature = 'test1';/*** Execute the command.** @return void*/public function handle(){//$output = new ConsoleOutput();$progressBar = new ProgressBar($output, 1000);$progressBar->setFormat(" %elapsed:6s%/%estimated:-6s% 內(nèi)存消耗: %memory:6s%\n%current%/%max% [%bar%] %percent:3s%%");foreach (range(1, 1000) as $_) {usleep(5000);$progressBar->advance();}$progressBar->finish();echo "\n";} }
效果:
?
輸出多個進(jìn)度條:
$progressBar->start(); print "\n"; $progressBar->start();?中間需要打印一個換行符
?
轉(zhuǎn)載于:https://www.cnblogs.com/eleven24/p/9134303.html
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的laravel 命令行输出进度条的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c# maiform父窗体改变动态的gr
- 下一篇: 漫谈 | “黎曼猜想”和区块链加密算法到