Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

321
Vistas
Symfony/Console: How to use multiple progress bars?

I have a command for Symfony/Console which downloads several files at once using Guzzle Pool. I already have Guzzle reporting the download progress for each file, that works fine.

Now I'd like to improve it using the ProgressBar helper from Symfony/Console.The problem is that all examples I found for the ProgressBar only use a single progress bar. I need several independent progress bars - one for each of the downloads. Can you give me some hint how to achieve that?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I found something here: [Console] A better progress bar #10356

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

$output = new ConsoleOutput();

$bar1 = new ProgressBar($output, 10);
$bar2 = new ProgressBar($output, 20);
$bar2->setProgressCharacter('#');
$bar1->start();
print "\n";
$bar2->start();

for ($i = 1; $i <= 20; $i++) {
    // up one line
    $output->write("\033[1A");
    usleep(100000);
    if ($i <= 10) {
        $bar1->advance();
    }
    print "\n";
    $bar2->advance();
}

Effect:

ProgressBar

You must move the console cursor to the appropriate line (up and down) before updating the bar. But it works. I confirm.

about 4 years ago · Santiago Trujillo Denunciar

0

With Symfony 4.1 this is supported without manual cursor-control, see https://symfony.com/doc/current/components/console/helpers/progressbar.html#console-multiple-progress-bars:

$section1 = $output->section();
$section2 = $output->section();

$progress1 = new ProgressBar($section1);
$progress2 = new ProgressBar($section2);

$progress1->start(100);
$progress2->start(100);

$i = 0;
while (++$i < 100) {
    $progress1->advance();

    if ($i % 2 === 0) {
         $progress2->advance(4);
    }

    usleep(50000);
}
about 4 years ago · Santiago Trujillo Denunciar

0

Laravel 5.6 / linux

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

$output = new ConsoleOutput();

$bar1 = new ProgressBar($output->section(), 10);
$bar2 = new ProgressBar($output->section(), 20);
$bar2->setProgressCharacter('#');
$bar1->start();
print "\n";
$bar2->start();

for ($i = 1; $i <= 20; $i++) {
    // up one line
    $output->write("\033[1A");
    usleep(100000);
    if ($i <= 10) {
        $bar1->advance();
    }
    print "\n";
    $bar2->advance();
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda