PHP code example of othyn / php-time-remaining

1. Go to this page and download the library: Download othyn/php-time-remaining 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/ */

    

othyn / php-time-remaining example snippets




use Othyn\TimeRemaining\TimeRemaining;

$timeRemaining = new TimeRemaining(100);
sleep(30); // Simulate some work being done.

$formattedProgress = $timeRemaining->getFormattedProgress(50);
echo $formattedProgress; // Output: [50% - 50 / 100][~ 0h 0m 30s remaining]



thyn\TimeRemaining\TimeRemaining;

$totalItems = 100;
$timeRemaining = new TimeRemaining($totalItems);



thyn\TimeRemaining\TimeRemaining;

$timeRemaining = new TimeRemaining();

// Code that fetches total items as $totalItems

$timeRemaining->setTotalItems($totalItems);



$formattedProgress = $timeRemaining->getFormattedProgress($currentItem);
echo $formattedProgress; // Output: [50% - 50 / 100][~ 0h 0m 30s remaining]



$customFormat = '[%d%% - %d / %d items][~ %dh %dm %ds left]';
$formattedProgressCustom = $timeRemaining->getFormattedProgress($currentItem, $customFormat);
echo $formattedProgressCustom; // Output: [50% - 50 / 100 items][~ 0h 0m 30s left]



$elapsedTime = $timeRemaining->getElapsedTime();
echo "Elapsed time: {$elapsedTime} seconds\n";



$currentItem = 50;
$progress = $timeRemaining->getPercentageProgress($currentItem);
echo "Progress: {$progress}%\n";



$estimatedTotalTime = $timeRemaining->getEstimatedTotalTime($currentItem);
echo "Estimated total time: {$estimatedTotalTime} seconds\n";



$remainingTime = $timeRemaining->getRemainingTime($currentItem);
echo "Remaining time: {$remainingTime} seconds\n";