Scheduling extension for Yii 1.1.* framework

1.0.0 2019-05-07 13:50 UTC

This package is auto-updated.

Last update: 2020-09-07 17:23:39 UTC


This extension is the port of omnilight/yii2-scheduling (


The preferred way to install this extension is through composer.

Either run

php composer.phar require anonymous-php/yii-scheduling "*"

or add

"anonymous-php/yii-scheduling": "*"

to the require section of your composer.json.


This project is inspired by the Laravel's Schedule component and tries to bring it's simplicity to the Yii framework. Quote from Laravel's documentation:

In the past, developers have generated a Cron entry for each console command they wished to schedule.
However, this is a headache. Your console schedule is no longer in source control,
and you must SSH into your server to add the Cron entries. Let's make our lives easier.

After installation you have to create console command extending Anonymous\Scheduling\ScheduleCommand class and implement schedule() method with your jobs inside:


class ScheduleCommand extends \Anonymous\Scheduling\ScheduleCommand
    protected function schedule(Schedule $schedule)

When setup will be finished just put single line into crontab:

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

You can put your schedule into the schedule.php file, or add it withing bootstrapping of your extension or application

Schedule examples

This extension is support all features of Laravel's Schedule, except environments and maintance mode.

Scheduling Closures

    // Do some task...


Scheduling Terminal Commands

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

Running command of your application

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

Frequent Jobs




Daily Jobs


Daily Jobs At A Specific Time (24 Hour Time)


Twice Daily Jobs


Job That Runs Every Weekday


Weekly Jobs


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

Monthly Jobs


Job That Runs On Specific Days


Only Allow Job To Run When Callback Is True

    return true;

E-mail The Output Of A Scheduled Job

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

        ->setSubject('Cronjob notification')

Preventing Task Overlaps


Used by default FileMutex or 'mutex' application component (

Running Tasks On One Server

To utilize this feature, you must config mutex in the application component, except the FileMutex: Yiisoft\Mutex\MysqlMutex,Yiisoft\Mutex\PgsqlMutex,Yiisoft\Mutex\OracleMutex or Yiisoft\Mutex\RedisMutex. In addition, all servers must be communicating with the same central db/cache server.

Below shows the redis mutex demo:

'components' => [
    'mutex' => [
        'class' => 'Yiisoft\Mutex\RedisMutex',
        'redis' => [
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0,
$schedule->command('report generate')

Using addition functions

If you want to use thenPing method of the Event, you should add the following string to the composer.json of your app:

"guzzlehttp/guzzle": "~5.0"

Note about timezones

Please note, that this is PHP extension, so it use timezone defined in php config or in your Yii's configuration file, so set them correctly.