SymfonyWorld Online 2021 Winter Edition December 9 – 10, 2021 100% Online 25 talks and 10 workshops

New in Symfony 4.4: Better Control of Console Progress Bars

Contributed by
Gabriel Ostrolucký
in #26339.

Progress bars are one of the most popular features of the Console component. They allow to show progress information while the command runs, which is ideal for long-running commands.

The most difficult thing when creating some progress bars is how to define their redraw frequency with the setRedrawFrequency() method. If you redraw it too often, the progress bar flickers too much but if you redraw it not too often, the progress bar looks unresponsive.

An additional problem is that sometimes you don't know how fast or slow will the command progress (e.g. when downloading some file, copying files, etc.).

In Symfony 4.4 we've improved the Symfony Console progress bars with two new methods which will help you control the redraw frequency:

use Symfony\Component\Console\Helper\ProgressBar;

$progressBar = new ProgressBar($output, 50000);


The new minSecondsBetweenRedraws() and maxSecondsBetweenRedraws() methods will give you a greater control of the progress bar redraw frequency and will ensure that you don't redraw it either too much or too little.

Related to this, in Symfony 4.4 we've also set 0.1 as the value of the minSecondsBetweenRedraws property, so progress bars are not updated more than 10 times per second by default (see Pull Request #32424).

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 4.4: Better Control of Console Progress Bars

Tweet this


Will this also improve performance? I believe that if you update on every +1, and you do that for a loop of 50k, performance is dropping during the loop.
I guess the issue comes from your application. Usually it is caused by the garbage collector.
This will indeed improve performance in some cases. Redrawing the progress bar thousands of times per second won't work because of the IO on STDOUT necessary for that, which will become the bottleneck of your command.

That's actually the reason why such control was added in the first place with `setRedrawFrequency`.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.