PHPackages                             yii2mod/yii2-scheduling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. yii2mod/yii2-scheduling

ActiveYii2-extension

yii2mod/yii2-scheduling
=======================

Scheduling extension for Yii2 framework

1.1.1(8y ago)1630.2k↓16.7%91PHPPHP &gt;=5.6

Since Mar 3Pushed 6y ago4 watchersCompare

[ Source](https://github.com/yii2mod/yii2-scheduling)[ Packagist](https://packagist.org/packages/yii2mod/yii2-scheduling)[ RSS](/packages/yii2mod-yii2-scheduling/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (1)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 Schedule Extension
=======================

[](#yii2-schedule-extension)

This extension is the port of Laravel's Schedule component ()

[![Latest Stable Version](https://camo.githubusercontent.com/16f57ae8cff56f0d2e97ccd601ce310a494e4bc632d6e2e31ffb49a651286e60/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d7363686564756c696e672f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-scheduling) [![Total Downloads](https://camo.githubusercontent.com/7d19e7e30f16a71af1c9cf50c43b5fef102cf3807553ab8a676aa8395f8021a7/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d7363686564756c696e672f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-scheduling)[![License](https://camo.githubusercontent.com/d7c199394b7eb4a6ff4f3942320438bb6f3afad81dc1b8861e502ce3b4afb995/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d7363686564756c696e672f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-scheduling)[![Build Status](https://camo.githubusercontent.com/40eba0717445ab7917075cb96c18805131c71bc018557ad2f6120d383b22db77/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d7363686564756c696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-scheduling)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f17c1a5650ce5485cbd1079916dd6174e8da75810f13a37d58e0dc84ca841c33/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969326d6f642f796969322d7363686564756c696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yii2mod/yii2-scheduling/?branch=master)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require yii2mod/yii2-scheduling "*"

```

or add

```
"yii2mod/yii2-scheduling": "*"

```

to the `require` section of your composer.json.

Description
-----------

[](#description)

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 all you have to do is to put single line into crontab:

```
* * * * * php /path/to/yii yii schedule/run --scheduleFile=@path/to/schedule.php 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
-----------------

[](#schedule-examples)

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

**Scheduling Closures**

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

})->hourly();
```

**Scheduling Terminal Commands**

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

**Running command of your application**

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

**Frequent Jobs**

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

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

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

**Daily Jobs**

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

**Daily Jobs At A Specific Time (24 Hour Time)**

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

**Twice Daily Jobs**

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

**Job That Runs Every Weekday**

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

**Weekly Jobs**

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

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

**Monthly Jobs**

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

**Job That Runs On Specific Days**

```
$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();
```

**Only Allow Job To Run When Callback Is True**

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

**Only Allow Job To Run When `skip` Callback is False**

```
$schedule->command('foo')->monthly()->skip(function()
{
    return false;
});
```

**Set Custom Description For Scheduled Job**

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

**E-mail The Output Of A Scheduled Job**

```
$schedule->command('foo')->sendOutputTo($filePath)->emailOutputTo('foo@example.com');
```

**To see the list of registered tasks, you can use the `schedule/list` command as below:**

```
php yii schedule/list

+---+-------------------------------------+-------------+-----------------------------------------------------+
| # | Task                                | Expression  | Command to Run                                      |
+---+-------------------------------------+-------------+-----------------------------------------------------+
| 1 | Delete the logs older than week     | 0 0 * * 0 * | /usr/bin/php5 yii app/delete-logs-older-then-week   |
+---+-------------------------------------+-------------+-----------------------------------------------------+
```

How to use this extension in your application?
----------------------------------------------

[](#how-to-use-this-extension-in-your-application)

You should create the following file under `@console/config/schedule.php` (note: you can create file with any name and extension and anywere on your server, simpli ajust the name of the scheduleFile in the command below):

```
