alex-heifetz/progress-bar

PHP CLI progress bar

1.3.2 2024-08-24 19:35 UTC

This package is auto-updated.

Last update: 2025-08-08 14:20:16 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
  • It is possible to divide into 2 parts, for example with successful iterations and with erroneous ones
  • Flexibly responds to changes in window width
  • It is possible to configure the data update time

Why you might need this

Sometimes when running commands and long processes or testing commands, you want to see that the process is moving and not hanging in the middle. I would also like to understand the approximate completion time of the process. This library was created to solve these problems.

Installation & loading

Just add this line to your composer.json file:

"alex-heifetz/progress-bar": "^1.2"

or run

composer require seraph90/progress-bar

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;
// Passing total count of iterations 
$pb = new ProgressBar($count);

// Set the delay time between redrawings
$pb->setRenderDelay(100);

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

ProgresBar