zoukankan      html  css  js  c++  java
  • laravel 命令行输出进度条

    有时候我们想在命令行执行一些耗时的命令,我们可以利用 symfony 提供的进度条相关的类,来输出一个进度条,显示当前的处理进度。

    参考:http://symfony.com/doc/current/components/console/helpers/progressbar.html

    <?php
    
    namespace AppCommands;
    
    use AppConsoleCommandsBaseCommand;
    use IlluminateContractsBusSelfHandling;
    use SymfonyComponentConsoleHelperProgressBar;
    use SymfonyComponentConsoleOutputConsoleOutput;
    
    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%   内存消耗: %memory:6s%
    %current%/%max% [%bar%] %percent:3s%%");
    
            foreach (range(1, 1000) as $_) {
                usleep(5000);
                $progressBar->advance();
            }
    
            $progressBar->finish();
            echo "
    ";
        }
    }
    

      

    效果:

    输出多个进度条:

    $progressBar->start();
    print "
    ";
    $progressBar->start();
    

     中间需要打印一个换行符  

  • 相关阅读:
    Python-Matplotlib 12 多图figure
    Python-Matplotlib 11 子图-subplot
    Python Day16
    Python Day15
    Python Day13-14
    Python Day12
    Python Day11
    Python Day9-10
    Python Day8
    Python Day8
  • 原文地址:https://www.cnblogs.com/eleven24/p/9134303.html
Copyright © 2011-2022 走看看