PHP code example of slavkluev / yii2-job-progress

1. Go to this page and download the library: Download slavkluev/yii2-job-progress 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/ */

    

slavkluev / yii2-job-progress example snippets


'components' => [
    'queue' => [
        // ...
        'as progress' => \slavkluev\JobProgress\ProgressBehavior::class,
    ],
],

'controllerMap' => [
    // ...
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => null,
        'migrationNamespaces' => [
            // ...
            'slavkluev\JobProgress\migrations',
        ],
    ],
],
 php
class TestJob extends BaseObject implements \yii\queue\JobInterface
{
    public function execute($queue)
    {
        \Yii::$app->queue->setProgressMax(100);
        for ($i = 0; $i < 100; $i++) {
            \Yii::$app->queue->incrementProgress();
            sleep(1);
        }
    }
}
 php
$jobProgress = JobProgress::findByJobId($jobId);
echo $jobProgress->getProgressMax() . PHP_EOL;
echo $jobProgress->getProgressNow() . PHP_EOL;
echo $jobProgress->getPercent() . PHP_EOL;