PHP code example of anonymous-php / yii-scheduling

1. Go to this page and download the library: Download anonymous-php/yii-scheduling 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/ */

    

anonymous-php / yii-scheduling example snippets




class ScheduleCommand extends \Anonymous\Scheduling\ScheduleCommand
{
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('foo')->monthly();
    }
}

$schedule->call(function()
{
    // Do some task...

})->hourly();

$schedule->exec('composer self-update')->daily();

$schedule->command('migrate')->cron('* * * * *');

$schedule->command('foo')->everyFiveMinutes();

$schedule->command('foo')->everyTenMinutes();

$schedule->command('foo')->everyThirtyMinutes();

$schedule->command('foo')->daily();

$schedule->command('foo')->dailyAt('15:00');

$schedule->command('foo')->twiceDaily();

$schedule->command('foo')->weekdays();

$schedule->command('foo')->weekly();

// Schedule weekly job for specific day (0-6) and time...
$schedule->command('foo')->weeklyOn(1, '8:00');

$schedule->command('foo')->monthly();

$schedule->command('foo')->mondays();
$schedule->command('foo')->tuesdays();
$schedule->command('foo')->wednesdays();
$schedule->command('foo')->thursdays();
$schedule->command('foo')->fridays();
$schedule->command('foo')->saturdays();
$schedule->command('foo')->sundays();

$schedule->command('foo')->monthly()->when(function()
{
    return true;
});

$schedule->command('foo')->sendOutputTo($filePath)->processOutput(function ($textBody, $app) 
{
    if (trim($textBody) === '' ) {
        return;
    }

    $app->mailer
        ->compose()
        ->setTextBody($textBody)
        ->setSubject('Cronjob notification')
        ->setTo('[email protected]')
        ->send();
});

$schedule->command('foo')->withoutOverlapping();


'components' => [
    'mutex' => [
        'class' => 'Yiisoft\Mutex\RedisMutex',
        'redis' => [
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0,
        ]
    ],
],

$schedule->command('report generate')
                ->fridays()
                ->at('17:00')
                ->onOneServer();

php composer.phar 
json
"anonymous-php/yii-scheduling": "*"

* * * * * php /path/to/yii yii schedule run 1>> /dev/null 2>&1