Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Using Symfony progress bar without knowing the exact number of steps in advance

$
0
0

I have this example of how to use the Symfony progress bar helper

protected function execute(InputInterface $input, OutputInterface $output)    {    // Fake data source    $customers = [    ['John Doe', 'john.doe@mail.loc', '1983-01-16'],    ['Samantha Smith', 'samantha.smith@mail.loc', '1986-10-23'],    ['Robert Black', 'robert.black@mail.loc', '1978-11-18'],    ];    // Progress Bar Helper    $progress = new    \Symfony\Component\Console\Helper\ProgressBar($output,    count($customers));    $progress->start();    for ($i = 1; $i <= count($customers); $i++) {    sleep(5);    $progress->advance();    }    $progress->finish();    // Table Helper    $table = new \Symfony\Component\Console\Helper\Table($output);    $table->setHeaders(['Name', 'Email', 'DON'])    ->setRows($customers)    ->render();    }

Now, in the above example I gave, I was able to know in advance the total number of customers that will be export by using count(customers) as the 2nd argument of the progress bar.

Now, am creating a script that needed to download remote file which I have no idea how long it will take or the steps it will take before download will be complete.

My question is how can I create such script if I don't know in advance the number of steps that will be taking before hand?

NB: All examples I saw here and other places rarely(if at all) mention that


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>