PHP code example of glpzzz / yii2-cron

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

    

glpzzz / yii2-cron example snippets


'modules' => [
    'cron' => [
        'class' => \glpzzz\cron\Module::class,
        'scan'  => ['console\\controllers\\cron' => '@console/controllers/cron'],
    ],
],

'modules' => [
    'cron' => ['controllerNamespace' => 'console\\controllers\\cron'],
],

use glpzzz\cron\attributes\Cron;

class UsersController extends \yii\console\Controller
{
    #[Cron('send insurance-expiration alerts', '0 11 * * *')]
    public function actionNotifyForInsurance(): int { /* ... */ }

    // Repeatable -- schedule the same action twice with different params:
    #[Cron('daily new-job matches', '0 8 * * *', ['1'])]
    #[Cron('weekly new-job matches', '0 14 * * 5', ['7'])]
    public function actionNotifyUsersAboutNewJobs(int $daysSinceCreated): void { /* ... */ }
}

'modules' => ['cron' => ['components' => [
    'crontab'     => \glpzzz\cron\testing\FakeCrontab::class,
    'cronScanner' => \glpzzz\cron\testing\FakeCronScanner::class,
]]],