alex-heifetz / progress-bar
PHP CLI progress bar
1.4.0
2026-07-24 08:11 UTC
Requires
- php: >=7.4
- ext-pcntl: *
README
Features
- Compatible with PHP 7.4 and later
- Displays estimated completion time
- Separates successful and failed iterations
- Responds to terminal width changes
- Lets you configure the redraw interval
Why you might need this
When running long CLI commands, background jobs, or test scripts, it is useful to see that the process is still moving and estimate when it will finish. This library provides a compact progress bar for those cases.
Requirements
- PHP 7.4+
ext-pcntl- A terminal with ANSI escape sequence support
Installation & loading
Install the package with Composer:
composer require alex-heifetz/progress-bar
Or add it to your composer.json manually:
{
"require": {
"alex-heifetz/progress-bar": "^1.4"
}
}
A Simple Example
<?php // Import ProgressBar class into the global namespace use Heifetz\ProgressBar; // Load Composer's autoloader require 'vendor/autoload.php'; $count = 12000000; // Create an instance with the total number of iterations. $pb = new ProgressBar($count); // Set the redraw delay in milliseconds. $pb->setRenderDelay(100); // Optional: count errors separately. // Disable this if failed iterations should be counted as completed iterations. $pb->setSeparateErrors(true); for ($i = 0; $i < $count; $i++) { if (mt_rand(0, 5)) { // Advance the process by one iteration $pb->advance(); } else { // Advance the process by one iteration with error $pb->advanceError(); } } // We indicate the completion of the progress bar to render the final state $pb->finish();

