cshaptx4869 / http-crontab
接口化定时任务管理
Installs: 1 901
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 4
Open Issues: 0
pkg:composer/cshaptx4869/http-crontab
Requires
- php: >=7.0.0
 - ext-json: *
 - nikic/fast-route: ^1.3
 - workerman/crontab: ^1.0
 - workerman/mysql: ^1.0
 - workerman/workerman: ^4.0
 
This package is auto-updated.
Last update: 2025-10-07 09:16:01 UTC
README
概述
基于 Workerman + MySQL 的接口化秒级定时任务管理,兼容 Windows 和 Linux 系统。
定时器格式说明
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位,则最小时间粒度是分钟]
简单使用
- 新建 run.php
 
<?php require_once "./vendor/autoload.php"; use Fairy\HttpCrontab; date_default_timezone_set('PRC'); //数据库配置 //启动脚本后会自行创建所需的数据表 //定时器任务执行日志按月自动分表 $dbConfig = [ 'hostname' => '127.0.0.1', 'hostport' => '3306', 'username' => 'root', 'password' => 'root', 'database' => 'test', 'charset' => 'utf8mb4' ]; //启动后默认监听 http://127.0.0.1:2345 //可在new的时候传递第一个参数改变监听地址 (new HttpCrontab())->setDebug(true) ->setName('System Crontab') ->setDbConfig($dbConfig) ->run();
- 启动服务
 
集成项目
easyadmin 是基于 ThinkPHP6.1 和 Layui2.7 的快速开发的后台管理系统。
- 启动服务
 
$ php think crontab -h Usage: crontab [options] [--] <action> Arguments: action start|stop|restart|reload|status|connections Options: -d, --daemon Run the http crontab server in daemon mode. --name[=NAME] Crontab name [default: "Crontab Server"] --debug Print log -h, --help Display this help message -V, --version Display this console version -q, --quiet Do not output any message --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
- UI操作界面
 
定时器接口说明
PING
基本信息
Path: /crontab/ping
Method: GET
接口描述:
{
  "code": 200,
  "data": "pong",
  "msg": "信息调用成功!"
}
请求参数
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | string | 非必须 | |||
| msg | string | 非必须 | 
修改
基本信息
Path: /crontab/modify
Method: POST
接口描述:
{
  "code": 200,
  "data": true,
  "msg": "信息调用成功!"
}
请求参数
Headers
| 参数名称 | 参数值 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| Content-Type | application/x-www-form-urlencoded | 是 | 
Body
| 参数名称 | 参数类型 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| id | text | 是 | 1 | |
| field | text | 是 | status | 字段[status; sort; remark; title] | 
| value | text | 是 | 1 | 值 | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | boolean | 非必须 | |||
| msg | string | 非必须 | 
列表
基本信息
Path: /crontab/index
Method: GET
接口描述:
{
  "code": 200,
  "data": {
    "list": [
      {
        "id": 1,
        "title": "输出 tp 版本",
        "type": 0,
        "frequency": "*/3 * * * * *",
        "shell": "php think version",
        "running_times": 3,
        "last_running_time": 1625636646,
        "remark": "没3秒执行",
        "sort": 0,
        "status": 1,
        "create_time": 1625636609,
        "update_time": 1625636609
      }
    ],
    "count": 1
  },
  "msg": "信息调用成功!"
}
请求参数
Query
| 参数名称 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|
| page | 是 | 1 | 页码 | 
| limit | 是 | 15 | 每页条数 | 
| filter | 否 | {"title":"输出 tp 版本"} | 检索字段值 | 
| op | 否 | {"title":"%*%"} | 检索字段操作 | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | object | 非必须 | |||
| ├─ list | object [] | 非必须 | item 类型: object  | ||
| ├─ id | number | 非必须 | |||
| ├─ title | string | 非必须 | |||
| ├─ type | number | 非必须 | |||
| ├─ frequency | string | 非必须 | |||
| ├─ shell | string | 非必须 | |||
| ├─ running_times | number | 非必须 | |||
| ├─ last_running_time | number | 非必须 | |||
| ├─ remark | string | 非必须 | |||
| ├─ sort | number | 非必须 | |||
| ├─ status | number | 非必须 | |||
| ├─ create_time | number | 非必须 | |||
| ├─ update_time | number | 非必须 | |||
| ├─ count | number | 非必须 | |||
| msg | string | 非必须 | 
删除
基本信息
Path: /crontab/delete
Method: POST
接口描述:
{
  "code": 200,
  "data": true,
  "msg": "信息调用成功!"
}
请求参数
Headers
| 参数名称 | 参数值 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| Content-Type | application/x-www-form-urlencoded | 是 | 
Body
| 参数名称 | 参数类型 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| id | text | 是 | 1,2 | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | boolean | 非必须 | |||
| msg | string | 非必须 | 
定时器池
基本信息
Path: /crontab/pool
Method: GET
接口描述:
{
  "code": 200,
  "data": [
    {
      "id": 1,
      "shell": "php think version",
      "frequency": "*/3 * * * * *",
      "remark": "没3秒执行",
      "create_time": "2021-07-07 13:43:29"
    }
  ],
  "msg": "信息调用成功!"
}
请求参数
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | object [] | 非必须 | item 类型: object  | ||
| ├─ id | number | 非必须 | |||
| ├─ shell | string | 非必须 | |||
| ├─ frequency | string | 非必须 | |||
| ├─ remark | string | 非必须 | |||
| ├─ create_time | string | 非必须 | |||
| msg | string | 非必须 | 
日志
基本信息
Path: /crontab/flow
Method: GET
接口描述:
{
  "code": 200,
  "data": {
    "list": [
      {
        "id": 12,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.115895",
        "create_time": 1625636673,
        "update_time": 1625636673
      },
      {
        "id": 11,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.104641",
        "create_time": 1625636670,
        "update_time": 1625636670
      },
      {
        "id": 10,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.106585",
        "create_time": 1625636667,
        "update_time": 1625636667
      },
      {
        "id": 9,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.10808",
        "create_time": 1625636664,
        "update_time": 1625636664
      },
      {
        "id": 8,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.107653",
        "create_time": 1625636661,
        "update_time": 1625636661
      },
      {
        "id": 7,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.105938",
        "create_time": 1625636658,
        "update_time": 1625636658
      },
      {
        "id": 6,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.10461",
        "create_time": 1625636655,
        "update_time": 1625636655
      },
      {
        "id": 5,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.109786",
        "create_time": 1625636652,
        "update_time": 1625636652
      },
      {
        "id": 4,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.115853",
        "create_time": 1625636649,
        "update_time": 1625636649
      },
      {
        "id": 3,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.16941",
        "create_time": 1625636646,
        "update_time": 1625636646
      },
      {
        "id": 2,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.109524",
        "create_time": 1625636643,
        "update_time": 1625636643
      },
      {
        "id": 1,
        "sid": 1,
        "command": "php think version",
        "output": "v6.0.7",
        "return_var": 0,
        "running_time": "0.108445",
        "create_time": 1625636640,
        "update_time": 1625636640
      }
    ],
    "count": 12
  },
  "msg": "信息调用成功!"
}
请求参数
Query
| 参数名称 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|
| page | 是 | 1 | 页码 | 
| limit | 是 | 15 | 每页条数 | 
| filter | 否 | {"sid":"1"} | 检索字段值 | 
| op | 否 | {"sid":"="} | 检索字段操作 | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | object | 非必须 | |||
| ├─ list | object [] | 非必须 | item 类型: object  | ||
| ├─ id | number | 必须 | |||
| ├─ sid | number | 必须 | |||
| ├─ command | string | 必须 | |||
| ├─ output | string | 必须 | |||
| ├─ return_var | number | 必须 | |||
| ├─ running_time | string | 必须 | |||
| ├─ create_time | number | 必须 | |||
| ├─ update_time | number | 必须 | |||
| ├─ count | number | 非必须 | |||
| msg | string | 非必须 | 
添加
基本信息
Path: /crontab/add
Method: POST
接口描述:
{
  "code": 200,
  "data": true,
  "msg": "信息调用成功!"
}
请求参数
Headers
| 参数名称 | 参数值 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| Content-Type | application/x-www-form-urlencoded | 是 | 
Body
| 参数名称 | 参数类型 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| title | text | 是 | 输出 tp 版本 | 任务标题 | 
| type | text | 是 | 0 | 任务类型[0请求url; 1执行sql; 2执行shell] | 
| frequency | text | 是 | */3 * * * * * | 任务频率 | 
| shell | text | 是 | php think version | 任务脚本 | 
| remark | text | 是 | 没3秒执行 | 备注 | 
| sort | text | 是 | 0 | 排序 | 
| status | text | 是 | 1 | 状态[0禁用; 1启用] | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | boolean | 非必须 | |||
| msg | string | 非必须 | 
重启
基本信息
Path: /crontab/reload
Method: POST
接口描述:
{
  "code": 200,
  "data": true,
  "msg": "信息调用成功!"
}
请求参数
Headers
| 参数名称 | 参数值 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| Content-Type | application/x-www-form-urlencoded | 是 | 
Body
| 参数名称 | 参数类型 | 是否必须 | 示例 | 备注 | 
|---|---|---|---|---|
| id | text | 是 | 1,2 | 
返回数据
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| code | number | 非必须 | |||
| data | boolean | 非必须 | |||
| msg | string | 非必须 |