alex-heifetz/progress-bar

PHP CLI progress bar

Maintainers

Package info

github.com/alex-heifetz/progress-bar

pkg:composer/alex-heifetz/progress-bar

Transparency log

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.4.0 2026-07-24 08:11 UTC

This package is auto-updated.

Last update: 2026-07-24 08:26:15 UTC


README

GitHub Release GitHub Downloads (all assets, all releases) GitHub License Packagist Dependency Version

Gif

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();

ProgressBar