PHPackages                             enscope/yii2-scheduler - 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. enscope/yii2-scheduler

ActiveYii2-extension

enscope/yii2-scheduler
======================

Yet another Yii2 Cron-like scheduler

1.0.4(7y ago)23931BSD-3-ClausePHP

Since Jun 2Pushed 7y agoCompare

[ Source](https://github.com/enscope/yii2-scheduler)[ Packagist](https://packagist.org/packages/enscope/yii2-scheduler)[ Docs](https://github.com/enscope/yii2-scheduler)[ RSS](/packages/enscope-yii2-scheduler/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (6)Used By (0)

yii2-scheduler
==============

[](#yii2-scheduler)

Yet another Yii2 Cron-like extension, which was created because I felt, I needed something else, that was available at the time. In case you like it, feel free to use it in your projects. Currently, it is running in production successfully for multiple months.

Basic Usage
-----------

[](#basic-usage)

Add `ConsoleController` to `controllerMap` in your `config.php`:

```
'controllerMap' => [
    ...
    'scheduler' => [
        'class' => \enscope\Scheduler\ConsoleController::className(),
        'tasks' => require dirname(__FILE__) . '/schedule.php',
    ],
    ...
],

```

Tasks can be loaded from external file or in-lined in `config.php`. Externalizing the tasks is recommended, then `schedule.php` can be like:

```
return [
    [
        'schedule' => '0 2 * * 1-5',
        'class' => 'Main\Notifications\ScheduledTask\NotificationsDigestTask',
    ],
    [
        'schedule' => '* * * * *',
        'class' => 'enscope\Scheduler\ScheduledTask\RunActionScheduledTask',
        'action' => 'mailer/send',
        'params' => [
            'quiet' => true,
        ],
    ],
];

```

This scheduler configuration contains two tasks, one that is run every work-day at 2am and one that is run each minute. As you can see, you can either reference class, sub-classing `BaseScheduledTask` (in principe, the task must implement `ScheduledTaskInteface`, allowing customization of the schedule configuration, but it is recommended to extend `BaseScheduledTask` and use default CRON-like configuration) or call any available action from another controller.

Tasks are executed in order of definition, as are present in `tasks` array.

**The scheduler itself should be run using CRON or other task scheduler and to allow for the most granularity, it should be run each minute.**

Scheduled Task Configuration
----------------------------

[](#scheduled-task-configuration)

Configuration of scheduled tasks closely follows CRON-like principles. The schedule configuration string is 5 part definition in following order:

```
* * * * *
^ ^ ^ ^ ^ day of week (0-6)
| | | | month (1-12)
| | | day of month (1-31)
| | hour (0-23)
| minute (0-59)

```

You can define intervals using hyphen, e.g. `0 2 * * 1-5` to run the task 2AM on weekdays, you can define cycles using slash, e.g. `*/5 * * * *` to run the task "every five minutes", you can specify multiple values separated by comma, e.g. `* 6,12,18 * * *` to run the task every 6 hours except midnight.

Implementing Custom Tasks
-------------------------

[](#implementing-custom-tasks)

All scheduled tasks must implement `ScheduledTaskInterface`, but this interface does not provide actual evaluation of correct time to run the task and will run the task every time, the scheduler is run.

This basic interface is simple:

```
interface ScheduledTaskInterface
{
    /**
     * Executes scheduled task, but task must determine, if it will
     * perform the job or not, based on internal scheduling mechanism.
     *
     * @param \DateTime        $time      Time of the scheduler invocation, that may be different
     *                                    from the current time, but all schedules must relate
     *                                    to this time when checking if schedule is satisfied
     * @param bool             $force     If true, task should run regardless of schedule
     *
     * @return bool TRUE, if the task was actually executed
     */
    public function execute(\DateTime $time, $force = false);
}

```

The comment says it all. To implement a scheduled task, you need to implement `execute(DateTime, boolean = false)` method. The task itself has no connection to task scheduler, it should have the configuration of the schedule included in itself. Simplicity of the interface is by design, to allow for more advanced scheduled task configuration, if ever needed. For most use-cases, it is sufficient to extend abstract `BaseScheduledTask`, which contains single abstract method `scheduledTask()`, that needs to be implemented. The class implements `execute(..)` method and evaluates satisfaction of the `schedule` automatically, running the task only when the conditions are satisfied (and the task is not forced).

Exceptions and Error Handling
-----------------------------

[](#exceptions-and-error-handling)

Task can throw any Exception and the Scheduler will handle it, reporting error on error output along with scheduled task name and exception message. After reporting the error, Scheduler will continue running other tasks in order as defined. If it is necessary to terminate `Scheduler` execution immediatelly, it is possible to use `TerminateScheduleException`, which will force `Scheduler` to terminate instantly with appropriate error message. Of course, another Scheduler execution will try to run tasks again.

###  Health Score

31

—

LowBetter than 70% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~176 days

Total

5

Last Release

2877d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d723755429510b3a3d9c4fb335c9a3a570be1865215f50f2239f4313ae2f62b7?d=identicon)[enscope](/maintainers/enscope)

---

Top Contributors

[![mx0r](https://avatars.githubusercontent.com/u/54171515?v=4)](https://github.com/mx0r "mx0r (4 commits)")

---

Tags

scheduled-taskstask-scheduleryii2yii2-cronyii2-extensionyii2-schedulerschedulercronyii2extension

### Embed Badge

![Health badge](/badges/enscope-yii2-scheduler/health.svg)

```
[![Health](https://phpackages.com/badges/enscope-yii2-scheduler/health.svg)](https://phpackages.com/packages/enscope-yii2-scheduler)
```

###  Alternatives

[roopz/yii2-imap

yii2 extension to read and process mails from IMAP and PHP

4095.2k](/packages/roopz-yii2-imap)[webtoolsnz/yii2-scheduler

A scheduled task runner for Yii2 applications

1879.3k](/packages/webtoolsnz-yii2-scheduler)[fedemotta/yii2-cronjob

Yii2 extension to help in the creation of automated console scripts

2233.3k](/packages/fedemotta-yii2-cronjob)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1356.4k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
