1. Go to this page and download the library: Download verseles/progressable 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/ */
use Verseles\Progressable;
class MyFirstTask
{
use Progressable;
public function __construct()
{
$this->setOverallUniqueName('my-job')->resetOverallProgress();
}
public function run()
{
foreach (range(1, 100) as $value) {
$this->setLocalProgress($value);
usleep(100000); // Sleep for 100 milliseconds
echo "Overall Progress: " . $this->getOverallProgress() . "%" . PHP_EOL;
}
}
}
use Verseles\Progressable;
class MySecondTask
{
use Progressable;
public function __construct()
{
$this->setOverallUniqueName('my-job');
}
public function run()
{
foreach (range(1, 100) as $value) {
$this->setLocalProgress($value);
usleep(100000); // Sleep for 100 milliseconds
echo "Overall Progress: " . $this->getOverallProgress() . "%" . PHP_EOL;
}
}
}
$overallUniqueName = 'test-without-laravel';
$my_super_storage = [];
$saveCallback = function ($key, $data, $ttl) use (&$my_super_storage) {
$my_super_storage[$key] = $data;
};
$getCallback = function ($key) use (&$my_super_storage) {
return $my_super_storage[$key] ?? [];
};
$obj1 = new class { use Progressable; };
$obj1
->setCustomSaveData($saveCallback)
->setCustomGetData($getCallback)
->setOverallUniqueName($overallUniqueName)
->resetOverallProgress()
->updateLocalProgress(25);
$obj2 = new class { use Progressable; };
$obj2
->setCustomSaveData($saveCallback)
->setCustomGetData($getCallback)
->setOverallUniqueName($overallUniqueName)
->updateLocalProgress(75);