PHP code example of petenelson / progress-estimator

1. Go to this page and download the library: Download petenelson/progress-estimator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

petenelson / progress-estimator example snippets




$items = get_large_list_of_items();
$count = count($items);

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

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

	// Perform some work on each item.
	some_long_running_process_here($items[$i]);

	// 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;
}