@@ -50,10 +50,15 @@ you can also set the current progress by calling the
50
50
51
51
If your platform doesn't support ANSI codes, updates to the progress
52
52
bar are added as new lines. To prevent the output from being flooded,
53
- adjust the
53
+ use the method :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::preventRedrawFasterThan `
54
+ (it writes to the output after every N seconds) and the method
54
55
:method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `
55
- accordingly. By default, when using a ``max ``, the redraw frequency
56
- is set to *10% * of your ``max ``.
56
+ (it writes to the output every N iterations). By default, redraw frequency is
57
+ **100ms ** or **10% ** of your ``max ``.
58
+
59
+ .. versionadded ::
60
+
61
+ The ``preventRedrawFasterThan() `` method was introduced in Symfony 4.4.
57
62
58
63
If you don't know the exact number of steps in advance, set it to a reasonable
59
64
value and then call the ``setMaxSteps() `` method to update it as needed::
@@ -285,17 +290,20 @@ to display it can be customized::
285
290
286
291
.. caution ::
287
292
288
- For performance reasons, be careful if you set the total number of steps
289
- to a high number. For example, if you're iterating over a large number of
290
- items, consider setting the redraw frequency to a higher value by calling
291
- :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `,
292
- so it updates on only some iterations ::
293
+ For performance reasons, Symfony redraws screen every 100ms. If this is too
294
+ fast or to slow for your application, use these methods:
295
+ :method: ` Symfony \\ Component \\ Console \\ Helper \\ ProgressBar::preventRedrawFasterThan `
296
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `
297
+ :method: ` Symfony \\ Component \\ Console \\ Helper \\ ProgressBar::forceRedrawSlowerThan ` ::
293
298
294
299
$progressBar = new ProgressBar($output, 50000);
295
300
$progressBar->start();
296
301
297
- // update every 100 iterations
302
+ // this redraws the screen every 100 iterations, but sets additional limits:
303
+ // don't redraw slower than 100ms (0.1) or faster than 200ms (0.2)
298
304
$progressBar->setRedrawFrequency(100);
305
+ $progressBar->forceRedrawSlowerThan(0.2);
306
+ $progressBar->preventRedrawFasterThan(0.1);
299
307
300
308
$i = 0;
301
309
while ($i++ < 50000) {
@@ -304,6 +312,11 @@ to display it can be customized::
304
312
$progressBar->advance();
305
313
}
306
314
315
+ .. versionadded ::
316
+
317
+ The ``forceRedrawSlowerThan `` and ``preventRedrawFasterThan() `` methods
318
+ were introduced in Symfony 4.4.
319
+
307
320
Custom Placeholders
308
321
~~~~~~~~~~~~~~~~~~~
309
322
0 commit comments