Artisan::output() for progress visualization).queue:work with real-time updates).symfony/console’s ProgressBar while offering simpler syntax and Laravel-specific optimizations.laravel/framework, spatie/laravel-activitylog).displayAlternateProgressBar()).setDetails() is not thread-safe by design (safe in Laravel’s single-process model but requires caution in custom multi-process setups).CI or non-interactive shells via php_sapi_name() checks.symfony/console’s ProgressBar if UTF-8 fails.Artisan::output() calls, or only for long-running tasks (>2 seconds)?setDetails() calls in high-frequency loops (e.g., 1000+ updates)?| Use Case | Implementation Example | Benefit |
|---|---|---|
| Artisan Commands | Replace Artisan::line() with progress bars |
Instant feedback for migrate, seed |
| Queue Workers | Wrap Job::handle() with progress updates |
Visualize queue:work processing |
| Migrations | Show table creation/row insertion progress | Reduce "hanging" perception |
| API Batch Jobs | Track Guzzle/HTTP client request progress | Clarify rate-limited API calls |
| Deployments | Enhance Forge/Envoyer CLI scripts | Transparent rollout progress |
php artisan optimize:clear).setDetails() overhead).Artisan::output() in migrate, seed, and queue:work.config/cli-progress-bar.php) to enable/disable globally.--progress-bar-length=50).Command classes via dependency injection.
use Dariuszp\CliProgressBar;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
protected function execute(InputInterface $input, OutputInterface $output): int {
$bar = new CliProgressBar(100, 0, "Processing...");
$bar->display();
// Simulate work
for ($i = 0; $i <= 100; $i++) {
$bar->setDetails("Step $i/100");
sleep(0.1);
}
$bar->end();
return Command::SUCCESS;
}
handle() methods for real-time updates.
public function handle() {
$bar = new CliProgressBar(100);
$bar->display();
// Process job steps
foreach ($this->items as $item) {
$bar->increment();
}
$bar->end();
}
Alacritty, iTerm, and GNOME Terminal.migrate, seed).composer.json (e.g., ^1.0).monolog:
if (!str_contains(php_uname('s'), 'Windows')) {
$bar->display();
} else {
$bar->displayAlternateProgressBar();
logger()->warning('Windows UTF-8 fallback activated');
}
| Issue | Solution |
|---|---|
| Broken progress bar on Windows | Use displayAlternateProgressBar() |
Stale output on Ctrl+C |
Clear buffer on SIGINT |
| Slow rendering in loops | Batch setDetails() calls |
| Non-interactive shell errors | Detect STDIN and disable progress bars |
How can I help you explore Laravel packages today?