PHPackages                             axguowen/think-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. axguowen/think-crontab

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

axguowen/think-crontab
======================

A Simple Crontab Extend For ThinkPHP

143PHP

Since Apr 1Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

ThinkPHP 定时任务扩展
===============

[](#thinkphp-定时任务扩展)

一个简单的ThinkPHP定时任务扩展，定时功能基于Workerman4.1开发

支持多任务执行

支持定时执行闭包函数

支持定时执行类的动态方法

支持定时执行类的静态方法

执行器方法均支持依赖注入

安装
--

[](#安装)

```
composer require axguowen/think-crontab

```

配置
--

[](#配置)

首先配置config目录下的crontab.php配置文件。 配置项说明：

```
return [
    // 计划任务Worker实例名称
    'name' => 'think-crontab',
    // 是否以守护进程启动
    'daemonize' => false,
    // 内容输出文件路径
    'stdout_file' => '',
    // pid文件路径
    'pid_file' => '',
    // 日志文件路径
    'log_file' => '',
    // 任务列表
    'task_list' => [
        [
            // 类型为普通任务
            'type' => 'task',
            // 任务名称
            'name' => '执行闭包函数',
            // 间隔时间, 单位: 秒
            'interval' => 2,
            // 执行器，支持闭包、类的动态方法、类的静态方法，支持参数依赖注入
            'handler' => function(\think\App $app){
                echo 'ThinkPHP v' . $app->version() . PHP_EOL;
            }
        ],
        [
            // 类型为普通任务
            'type' => 'task',
            // 任务名称
            'name' => '执行类的静态方法',
            // 间隔时间, 单位: 秒
            'interval' => 4,
            // 执行器，支持闭包、类的动态方法、类的静态方法，支持参数依赖注入
            'handler' => \app\crontab\Handler::class . '::staticMethod',
        ],
        [
            // 类型为分组任务
            'type' => 'group',
            // 分组名称
            'name' => '动态方法测试分组',
            // 分组任务列表
            'tasks' => [
                [
                    // 任务名称
                    'name' => '执行类的动态方法',
                    // 间隔时间, 单位: 秒
                    'interval' => 6,
                    // 这里实例化Handler类后执行publicMethod方法
                    'handler' => [\app\crontab\Handler::class, 'publicMethod'],
                ],
                [
                    // 任务名称
                    'name' => '不指定动态方法则默认执行类的handle方法',
                    // 间隔时间, 单位: 秒
                    'interval' => 8,
                    // 此时\app\crontab\Handler类中必须要有handle方法
                    'handler' => \app\crontab\Handler::class,
                ],
            ],
        ],
    ],
];
```

启动停止
----

[](#启动停止)

定时任务的启动停止均在命令行控制台操作，所以首先需要在控制台进入tp目录

### 启动命令

[](#启动命令)

```
php think crontab start

```

要使用守护进程模式启动可以将配置项deamonize设置为true 或者在启动命令后面追加 -d 参数，如下：

```
php think crontab start -d

```

### 停止

[](#停止)

```
php think crontab stop

```

### 查看进程状态

[](#查看进程状态)

```
php think crontab status

```

注意
--

[](#注意)

Windows下不支持多进程设置，也不支持守护进程方式运行，正式生产环境请用Linux

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5bb2b3388238042a25cf42dc44e5ff84adc241510354abae9e91573556753205?d=identicon)[axguowen](/maintainers/axguowen)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[georgringer/numbered-pagination

Improved pagination for TYPO3

281.3M13](/packages/georgringer-numbered-pagination)[lambert/tree-shape

A simple way to generate a tree structure.

186.0k](/packages/lambert-tree-shape)

PHPackages © 2026

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