PHPackages                             anxu/crontab - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. anxu/crontab

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

anxu/crontab
============

crontab for yii2 framework

v0.1(8y ago)013MITPHPPHP &gt;=5.4.0

Since Dec 13Pushed 8y ago1 watchersCompare

[ Source](https://github.com/anxu1212/crontab)[ Packagist](https://packagist.org/packages/anxu/crontab)[ RSS](/packages/anxu-crontab/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Yii2 的插件，管理所有后台定时任务，不用修改 crontab

### 注意

[](#注意)

无法在window系统服务器中运行

用法
==

[](#用法)

通过 `composer` 安装

```
composer require anxu/crontab:"*"

```

Yii2 console 脚本，示例如下：

```
namespace app\commands;

use yii\console\Controller;
use anxu\Crontab\Crontab;

class DemoController extends Controller
{
    public function actionIndex()
    {
        // 从数据库获取执行的任务
        $jobs=[
            [
                'name'=>'1',
                'schedule'=>'* * * * *',
                'command'=>'date',
                'output'=>'log/log.log'
            ],[
                'name'=>'2',
                'schedule'=>'* * * * *',
                'command'=>'echo "test2"',
                'output'=>'log/log.log'
            ]
        ];

        $a  = new Crontab();
        $a->add($jobs);
        $a->run();
    }
}
```

将上面的脚本加入`crontab`中，如下所示：

```
* * * * * /path/to/project/yii demo/index 1>> /dev/null 2>&1

```

最后，启动crontab

属性说明备注`name`任务名字必须，唯一；如果重复则是当作相同任务`schedule`任务执行时间必须，支持`"* * * * *"`也支持`"Y-m-d H:i:s"``command`命令必须， shell 命令`output`命令输入路径如果命令有输出，则可以指定输出位置> "Y-m-d H:i:s" 格式，后面的 秒s 会被忽略；

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

3075d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cc928d4a136fa896226e760d2ed271477ac353a20a4ee930bd44d2608ccaf19?d=identicon)[anxu](/maintainers/anxu)

---

Tags

yii2crontab

### Embed Badge

![Health badge](/badges/anxu-crontab/health.svg)

```
[![Health](https://phpackages.com/badges/anxu-crontab/health.svg)](https://phpackages.com/packages/anxu-crontab)
```

###  Alternatives

[webtoolsnz/yii2-scheduler

A scheduled task runner for Yii2 applications

1881.1k](/packages/webtoolsnz-yii2-scheduler)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

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