Skip to content
PHP library to estimate time remaining for a list of long-running tasks
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
tests
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
composer.json
composer.lock
examples.php
phpcs.xml.dist
phpunit.xml.dist

README.md

Progress Estimator

PHP library to estimate time remaining for a list of tasks.

Build Status Percentage of issues still open

When processing a batch of items that takes a long time to run, this library can be used to to calculate and display the estimated time remaining.

Processing 12 items
[1/12]: Bacon ipsum dolor amet (0:35)
[2/12]: Cow porchetta labore shankle (0:33)
[3/12]: Filet mignon porchetta eiusmod tri-tip (0:28)
[4/12]: Venison aliqua, ad brisket pariatur (0:22)
[5/12]: Turkey reprehenderit picanha (0:18)
[6/12]: Turducken fatback ground round (0:16)
[7/12]: Strip steak leberkas laborum (0:12)
[8/12]: Pork belly excepteur buffalo (0:09)
[9/12]: ham chuck ipsum nostrud jerky (0:07)
[10/12]: Rump shank jalapeno (0:05)
[11/12]: Pancetta chicken do spare ribs, (0:02)
[12/12]: Meatball tenderloin picanha (0:00)

Usage

First, install the package using composer. composer require petenelson/progress-estimator. Some example code below, and be sure to check the examples.php file for a working implementation.

require_once __DIR__ . '/vendor/autoload.php';

// Create the progress estimator.
$estimator = new \PHPEstimator\ProgressEstimator(count($items));

// Loop through the list of items to process.
for ($i=0; $i < 100; $i++) {

	// Perform some work.
	some_long_running_process_here();

	// Increments the counter and saves the execution time of that item.
	$estimator->tick();

	// Display the current item processed and estimated time remaining.
	$output = sprintf(
		'Processed: %1$s (%2$s)' . PHP_EOL,
		$i,
		$estimator->formatTime($estimator->timeLeft())
	);

	echo $output;
}
You can’t perform that action at this time.