PHPackages                             creatcode/crontab-task - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. creatcode/crontab-task

ActiveThink-extend[Queues &amp; Workers](/categories/queues)

creatcode/crontab-task
======================

适用于tp5和tp6的秒级定时任务

v1.0.1(2y ago)017Apache-2.0PHPPHP &gt;=7.0

Since Jun 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/creatcode/crontab-task)[ Packagist](https://packagist.org/packages/creatcode/crontab-task)[ RSS](/packages/creatcode-crontab-task/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Crontab-task
============

[](#crontab-task)

适用于Thinkphp的秒级定时任务
==================

[](#适用于thinkphp的秒级定时任务)

基于 [http-crontab](https://github.com/yzh52521/http-crontab) 修改

概述
--

[](#概述)

基于 **Workerman** 的秒级定时任务管理，兼容 Windows 和 Linux 系统。支持thinkphp5.0，5.1，6.\*

- **如果开启任务锁，使用之前请先在缓存配置添加redis驱动配置**
- 建议搭配 [creatcode/crontab-expression](https://github.com/creatcode/crontab-expression)，支持秒级别表达式的生成和校验

crontab格式说明：
------------

[](#crontab格式说明)

```
0   1   2   3   4   5
|   |   |   |   |   |
|   |   |   |   |   +------ day of week (0 - 6) (Sunday=0)
|   |   |   |   +------ month (1 - 12)
|   |   |   +-------- day of month (1 - 31)
|   |   +---------- hour (0 - 23)
|   +------------ min (0 - 59)
+-------------- sec (0-59)[可省略，如果没有0位,则最小时间粒度是分钟]

```

```
-具体格式说明可查看附录部分crontab表达式详解
```

#### 启动命令

[](#启动命令)

```
php think crontask [start/stop...]
--debug 可用于调试打印

```

#### 任务分类

[](#任务分类)

- Url 任务：可以指定一个url地址来请求
- Class 任务：必须指定带有 命名空间的类名，并且实现一个 public 属性的方法：默认为execute， 方法返回值为 bool/string类型，支持自定义方法名 事例：target='app\\common\\model\\User@check' @后面是方法
- Command 任务：请先按照 thinkphp 官方文档定义好执行命令，再新增任务，输入定义的命令即可 e.g: version
- Shell 任务：输入定义的 shell命令即可 e.g: ps -ef | grep php
- Sql 任务：可直接执行sql语句 e.g: select 1

调用方式
====

[](#调用方式)

```
use Creatcode\Crontask\Client;
$param = [
    'method' => 'index',
    'args'   => ['limit' => 10, 'page' => 1]
];
$client = Client::instance()->request($param);
```

- 任务列表 index

```
参数：page,limit,?where

```

- 添加任务 add

```
参数：[必选] title，type，rule，target，?parameter
      [可选] remark，sort，status，singleton

```

- 修改任务 edit

```
参数：id, param(要更新的数据数组)

```

- 任务详情 read

```
参数：id

```

- 修改定时器状态 modify

```
参数：id，status

```

- 重启任务 reload

```
参数：id

```

- 删除任务 delete

```
参数：id

```

- 日志列表 flow

```
参数：page,limit,?where

```

- 定时器池 pool
- 心跳 ping
- 执行一次 runone

```
参数：id

```

附录
--

[](#附录)

### Cron表达式详解

[](#cron表达式详解)

- 这里是列表文本这里是列表文本Cron表达式是一个字符串，字符串以5或6个空格隔开，分为6或7个域，每一个域代表一个含义，Cron有如下两种语法格式：

（1）Seconds Minutes Hours DayofMonth Month DayofWeek Year

（2）Seconds Minutes Hours DayofMonth Month DayofWeek

### 一、结构

[](#一结构)

 corn表达式从左到右（用空格隔开）：秒 分 小时 月份中的日期 月份 星期中的日期 年份

### 二、各字段的含义

[](#二各字段的含义)

字段允许值允许的特殊字符秒（Seconds）0~59的整数, - \* / 四个字符分（Minutes）0~59的整数, - \* / 四个字符小时（Hours）0~59的整数, - \* / 四个字符日期（DayofMonth）1~31的整数（但是你需要考虑你月的天数）,- \* ? / L W C 八个字符月份（Month）1~12的整数或者 JAN-DEC, - \* / 四个字符星期（DayofWeek）1~7的整数或者 SUN-SAT （1=SUN）, - \* ? / L C # 八个字符年(可选，留空)（Year）1970~2099, - \* / 四个字符#### 注意事项：

[](#注意事项)

 每一个域都使用数字，但还可以出现如下特殊字符，它们的含义是：

 （1）\* :表示匹配该域的任意值。假如在Minutes域使用\*, 即表示每分钟都会触发事件。

 （2）?：只能用在DayofMonth和DayofWeek两个域。它也匹配域的任意值，但实际不会。因为DayofMonth和DayofWeek会相互影响。例如想在每月的20日触发调度，不管20日到底是星期几，则只能使用如下写法： 13 13 15 20 \* ?, 其中最后一位只能用？，而不能使用\*，如果使用\*表示不管星期几都会触发，实际上并不是这样。

 （3）-：表示范围。例如在Minutes域使用5-20，表示从5分到20分钟每分钟触发一次

 （4）/：表示起始时间开始触发，然后每隔固定时间触发一次。例如在Minutes域使用5/20,则意味着5分钟触发一次，而25，45等分别触发一次.

 （5）,：表示列出枚举值。例如：在Minutes域使用5,20，则意味着在5和20分每分钟触发一次。

 （6）L：表示最后，只能出现在DayofWeek和DayofMonth域。如果在DayofWeek域使用5L,意味着在最后的一个星期四触发。

 （7）W:表示有效工作日(周一到周五),只能出现在DayofMonth域，系统将在离指定日期的最近的有效工作日触发事件。例如：在 DayofMonth使用5W，如果5日是星期六，则将在最近的
工作日：星期五，即4日触发。如果5日是星期天，则在6日(周一)触发；如果5日在星期一到星期五中的一天，则就在5日触发。另外一点，W的最近寻找不会跨过月份 。

 （8）LW:这两个字符可以连用，表示在某个月最后一个工作日，即最后一个星期五。

 （9）#:用于确定每个月第几个星期几，只能出现在DayofWeek域。例如在4#2，表示某月的第二个星期三。

### 三、常用表达式例子

[](#三常用表达式例子)

 （0）0/20 \* \* \* \* ? 表示每20秒 调整任务

 （1）0 0 2 1 \* ? 表示在每月的1日的凌晨2点调整任务

 （2）0 15 10 ? \* MON-FRI 表示周一到周五每天上午10:15执行作业

 （3）0 15 10 ? 6L 2002-2006 表示2002-2006年的每个月的最后一个星期五上午10:15执行作

 （4）0 0 10,14,16 \* \* ? 每天上午10点，下午2点，4点

 （5）0 0/30 9-17 \* \* ? 朝九晚五工作时间内每半小时

 （6）0 0 12 ? \* WED 表示每个星期三中午12点

 （7）0 0 12 \* \* ? 每天中午12点触发

 （8）0 15 10 ? \* \* 每天上午10:15触发

 （9）0 15 10 \* \* ? 每天上午10:15触发

 （10）0 15 10 \* \* ? \* 每天上午10:15触发

 （11）0 15 10 \* \* ? 2005 2005年的每天上午10:15触发

 （12）0 \* 14 \* \* ? 在每天下午2点到下午2:59期间的每1分钟触发

 （13）0 0/5 14 \* \* ? 在每天下午2点到下午2:55期间的每5分钟触发

 （14）0 0/5 14,18 \* \* ? 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发

 （15）0 0-5 14 \* \* ? 在每天下午2点到下午2:05期间的每1分钟触发

 （16）0 10,44 14 ? 3 WED 每年三月的星期三的下午2:10和2:44触发

 （17）0 15 10 ? \* MON-FRI 周一至周五的上午10:15触发

 （18）0 15 10 15 \* ? 每月15日上午10:15触发

 （19）0 15 10 L \* ? 每月最后一日的上午10:15触发

 （20）0 15 10 ? \* 6L 每月的最后一个星期五上午10:15触发

 （21）0 15 10 ? \* 6L 2002-2005 2002年至2005年的每月的最后一个星期五上午10:15触发

 （22）0 15 10 ? \* 6#3 每月的第三个星期五上午10:15触发

 注：

 （1）有些子表达式能包含一些范围或列表

 例如：子表达式（天（星期））可以为 “MON-FRI”，“MON，WED，FRI”，“MON-WED,SAT”

“\*”字符代表所有可能的值

 因此，“*”在子表达式（月）里表示每个月的含义，“*”在子表达式（天（星期））表示星期的每一天

 “/”字符用来指定数值的增量 例如：在子表达式（分钟）里的“0/15”表示从第0分钟开始，每15分钟 在子表达式（分钟）里的“3/20”表示从第3分钟开始，每20分钟（它和“3，23，43”）的含义一样

 “？”字符仅被用于天（月）和天（星期）两个子表达式，表示不指定值 当2个子表达式其中之一被指定了值以后，为了避免冲突，需要将另一个子表达式的值设为“？”

 “L” 字符仅被用于天（月）和天（星期）两个子表达式，它是单词“last”的缩写 但是它在两个子表达式里的含义是不同的。 在天（月）子表达式中，“L”表示一个月的最后一天 在天（星期）自表达式中，“L”表示一个星期的最后一天，也就是SAT

 如果在“L”前有具体的内容，它就具有其他的含义了

 例如：“6L”表示这个月的倒数第６天，“FRIL”表示这个月的最一个星期五 注意：在使用“L”参数时，不要指定列表或范围，因为这会导致问题

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

737d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24988596?v=4)[Moto](/maintainers/creatcode)[@creatcode](https://github.com/creatcode)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.6M31](/packages/league-geotools)[illuminate/bus

The Illuminate Bus package.

6046.3M542](/packages/illuminate-bus)[uecode/qpush-bundle

Asynchronous processing for Symfony using Push Queues

1672.5M2](/packages/uecode-qpush-bundle)[saithink/saiadmin

webman plugin

28211.5k1](/packages/saithink-saiadmin)[belvg/module-sqs

N/A

1544.6k](/packages/belvg-module-sqs)[mayconbordin/l5-stomp-queue

Stomp Queue Driver for Laravel 5

121.1k](/packages/mayconbordin-l5-stomp-queue)

PHPackages © 2026

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