PHPackages                             ycl123/queue - 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. ycl123/queue

ActiveLibrary[Queues &amp; Workers](/categories/queues)

ycl123/queue
============

基于 Workerman4 的定时任务队列。

v1.0.1(4y ago)1431Apache-2.0PHPPHP &gt;=7.2

Since May 29Pushed 4y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (4)Versions (3)Used By (1)

基于 Workerman4 的定时任务队列。
======================

[](#基于-workerman4-的定时任务队列)

[![Total Downloads](https://camo.githubusercontent.com/dc2d4faed0adf66e4602ae92b9d3ea99f371ae4b9dece0c385093ddb0651ae6a/68747470733a2f2f706f7365722e707567782e6f72672f79636c3132332f71756575652f646f776e6c6f616473)](https://packagist.org/packages/ycl123/queue)[![Latest Stable Version](https://camo.githubusercontent.com/48736009a01279a37ad0677ecf25ce360e0812c5f5ce65314df1f861c74f8e0d/68747470733a2f2f706f7365722e707567782e6f72672f79636c3132332f71756575652f762f737461626c65)](https://packagist.org/packages/ycl123/queue)[![PHP Version](https://camo.githubusercontent.com/facf49f38d3f6bf192c14ce71a5e2479a4641044e627d4b7a27e4298a3002704/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e322d3838393242462e737667)](http://www.php.net/)[![License](https://camo.githubusercontent.com/a6a58cab24c2bb65dd593d575f420c40d3b01b31bd61b176e8db07f199d4232f/68747470733a2f2f706f7365722e707567782e6f72672f79636c3132332f71756575652f6c6963656e7365)](https://packagist.org/packages/ycl123/queue)

参考
--

[](#参考)

[think-queue](https://github.com/top-think/think-queue)
[workerman-queue](https://github.com/walkor/workerman-queue)

主要特性
----

[](#主要特性)

- 支持cron定时执行
- 支持指定时间执行

composer 安装
-----------

[](#composer-安装)

```
composer require ycl123/queue

```

配置
--

[](#配置)

键默认值类型说明context\[\]arraysocket 上下文选项 [参考](http://doc.workerman.net/worker/construct.html)con\_content\[\]arrayAsyncTcpConnection 上下文选项 [参考](http://doc.workerman.net/async-tcp-connection/construct.html)socket127.0.0.1:9889string监听地址 [参考](http://doc.workerman.net/worker/construct.html)count1int进程数 [参考](http://doc.workerman.net/worker/count.html)task\_concurrent50int最大任务并发数task\_topic\_concurrent10int最大任务主题并发数task\_retry\_time\_interval10int任务重试时间间隔(秒)task\_timeout\_expired\_time60int任务超时过期时间(秒)nameYcl123 queue servicestringWorker实例的名称 [参考](http://doc.workerman.net/worker/name.html)stdoutFile/dev/nullstring以守护进程方式(-d启动)运行时终端的输出重定向文件路径 [参考](http://doc.workerman.net/worker/stdout-file.html)pidFile\_\_DIR\_\_ . '/../worker\_ycl123\_queue.pid'stringworkerman进程的pid文件路径 [参考](http://doc.workerman.net/worker/pid-file.html)logFile\_\_DIR\_\_ . '/../worker\_ycl123\_queue.log'stringworkerman日志文件位置 [参考](http://doc.workerman.net/worker/log-file.html)reloadabletruebool当前Worker实例是否可以reload [参考](http://doc.workerman.net/worker/reloadable.html)daemonizefalsebool是否以daemon(守护进程)方式运行 [参考](http://doc.workerman.net/worker/daemonize.html)connection\[\]array：非thinkphp项目
string：thinkphp项目array：connections中的键值
string：connections中的键名
[ThinkORM开发指南](https://www.kancloud.cn/manual/think-orm)
[数据库配置](https://www.kancloud.cn/manual/think-orm/1257999)is\_cron\_schedulertruebool是否开启cron调度器，开启后每秒调度一次time\_scheduler\_time\_interval1int|float时间调度器执行时间间隔(秒)，设置为0则不进行调度，支持小数distributor\_time\_interval1int|float分发器执行时间间隔(秒)，设置为0则不执行分发，支持小数queue\_time\_interval1int|float队列调度执行时间间隔(秒)，设置为0则不进行调度，支持小数overdue\_time\_interval30int|float处理逾期任务时间间隔(秒)，设置为0则不进行处理，支持小数lognullnull|callable(Exception|string $exception)日志记录回调，不设置将使用worker的日志记录task\_dirs\[\]array任务目录定义，会自动扫描目录下的所有任务类
key：目录的命名空间
value：绝对路径
例：\['app\\command' =&gt; '/www/wwwroot/tp6/app/command'\]task\_class\[\]array任务类定义
例：\[Aa::class, Bb::class\]cron规则
------

[](#cron规则)

```
0    1    2    3    4    5    6
*    *    *    *    *    ?    *
-    -    -    -    -    -    -
|    |    |    |    |    |    |
|    |    |    |    |    |    +----- year (1970 - 2099) [, - * /] 低于7段表示不指定
|    |    |    |    |    +----- day of week (0 - 6) (Sunday=0) [, - * / ? W (0-6)L (0-6)#(1-5)]
|    |    |    |    +----- month (1 - 12) [, - * /]
|    |    |    +------- day of month (1 - 31) [, - * / ? L LW (1-31)W]
|    |    +--------- hour (0 - 23) [, - * /]
|    +----------- minute (0 - 59) [, - * /]
+------------- second (0 - 59) [, - * /] 低于6段表示不指定

,: 表示列出枚举值
-: 表示范围
*: 表示匹配该域的任意值
/: 表示起始时间开始触发，然后每隔固定时间触发一次
?: 表示不指定，只能用在day of month和day of week两个域，并且必须也只能有一个为 ?
L: 表示某月的最后一天
W: 表示有效工作日(1-5)
LW: 表示某月的最后一个工作日
(0-6)L: 表示某月的最后一个星期几(0-6)
(1-31)W: 表示离指定日期(1-31)最近的一个工作日，若指定日期大于当月最大日期则不触发
(0-6)#(1-5): 表示某月的第几个(1-5)星期几(0-6)

```

表结构
---

[](#表结构)

```
CREATE TABLE `task_scheduler`
(
    `id`               int(11) unsigned    NOT NULL AUTO_INCREMENT COMMENT '主键',
    `scheduler_type`   tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '任务类型:1=cron,2=time',
    `scheduler_status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '任务状态:1=正常,2=禁用',
    `scheduler_rule`   varchar(100)        NOT NULL DEFAULT '' COMMENT '调度器规则',
    `task_topic`       varchar(100)        NOT NULL DEFAULT '' COMMENT '任务主题',
    `task_data`        json                         DEFAULT NULL COMMENT '任务数据',
    `create_time`      int(10) unsigned    NOT NULL DEFAULT '0' COMMENT '创建时间',
    `update_time`      int(10) unsigned    NOT NULL DEFAULT '0' COMMENT '更新时间',
    PRIMARY KEY (`id`),
    KEY `idx_search1` (`scheduler_status`, `scheduler_type`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='调度器';

CREATE TABLE `task_distributor`
(
    `id`             int(11) unsigned    NOT NULL AUTO_INCREMENT COMMENT '主键',
    `scheduler_id`   int(11)             NOT NULL DEFAULT '0' COMMENT '调度器id',
    `task_topic`     varchar(100)        NOT NULL DEFAULT '' COMMENT '任务主题',
    `task_data`      json                         DEFAULT NULL COMMENT '任务数据',
    `task_count`     int(7) unsigned     NOT NULL DEFAULT '0' COMMENT '任务数量',
    `execute_status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '执行状态:1=待执行,2=执行中,3=执行成功,4=执行失败,5=已取消',
    `execute_result` text COMMENT '执行结果',
    `create_time`    int(10) unsigned    NOT NULL DEFAULT '0' COMMENT '创建时间',
    `start_time`     int(10) unsigned    NOT NULL DEFAULT '0' COMMENT '开始时间',
    `end_time`       int(10) unsigned    NOT NULL DEFAULT '0' COMMENT '结束时间',
    PRIMARY KEY (`id`),
    KEY `idx_search1` (`execute_status`),
    KEY `idx_search2` (`task_topic`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='分发器';

CREATE TABLE `task_queue`
(
    `id`                int(11) unsigned    NOT NULL AUTO_INCREMENT COMMENT '主键',
    `distributor_id`    int(11)             NOT NULL DEFAULT '0' COMMENT '分发器id',
    `task_topic`        varchar(100)        NOT NULL DEFAULT '' COMMENT '任务主题',
    `task_data`         json                         DEFAULT NULL COMMENT '任务数据',
    `execute_status`    tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '执行状态:1=待执行,2=执行中,3=执行成功,4=执行失败,5=已取消',
    `execute_result`    text COMMENT '执行结果',
    `execute_count`     int(5) unsigned     NOT NULL DEFAULT '0' COMMENT '执行次数',
    `max_execute_count` int(5) unsigned     NOT NULL DEFAULT '0' COMMENT '最大执行次数',
    `create_time`       int(10)             NOT NULL DEFAULT '0' COMMENT '创建时间',
    `start_time`        int(10)             NOT NULL DEFAULT '0' COMMENT '开始时间',
    `next_execute_time` int(10)             NOT NULL DEFAULT '0' COMMENT '下次执行时间',
    `end_time`          int(10)             NOT NULL DEFAULT '0' COMMENT '结束时间',
    PRIMARY KEY (`id`),
    KEY `idx_search1` (`execute_status`, `task_topic`),
    KEY `idx_search2` (`distributor_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='队列';

CREATE TABLE `task_queue_log`
(
    `id`             int(11) unsigned    NOT NULL AUTO_INCREMENT COMMENT '主键',
    `queue_id`       int(11)             NOT NULL DEFAULT '0' COMMENT '队列id',
    `execute_status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '执行状态:1=执行中,2=执行成功,3=执行失败,4=已取消',
    `execute_result` text COMMENT '执行结果',
    `start_time`     int(10)             NOT NULL DEFAULT '0' COMMENT '开始时间',
    `end_time`       int(10)             NOT NULL DEFAULT '0' COMMENT '结束时间',
    PRIMARY KEY (`id`),
    KEY `idx_search1` (`queue_id`),
    KEY `idx_search2` (`execute_status`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='队列日志';
```

使用
--

[](#使用)

> 新建一个任务执行文件`TestTask.php`

```
namespace ycl123\queue;

class TestTask extends Task
{
    public function run(array $taskData): Result
    {
        return Result::instanceSuccess();
    }

    public static function getTaskTopic(): string
    {
        return 'TEST_TASK';
    }
}
```

> 在建建一个启动`test.php`

```
use ycl123\queue\Start;
// 具体配置项请查看 config.php
$config = [
    'socket' => '127.0.0.1:9889',
    'count' => 1,
    // 非tp项目，tp项目 'connection' => 'mysql',
    'connection' => [
        'type' => 'mysql',
        'hostname' => '127.0.0.1',
        'database' => 'database',
        'username' => 'username',
        'password' => 'password',
        'hostport' => '3306',
        'charset' => 'utf8mb4',
        'debug' => true,
    ],
    'task_class' => [TestTask::class],
];
$start = new Start($config);
$start->run();
```

> 在数据中中执行下面的sql

```
INSERT INTO `task_scheduler`
(`scheduler_type`, `scheduler_status`, `scheduler_rule`, `task_topic`, `task_data`, `create_time`, `update_time`)
VALUES (1, 1, '* * * * * ?', 'TEST_TASK', '[]', 1621597020, 1621597020);
```

> 启动，其他启动参数请参考workerman[文档](http://doc.workerman.net/install/start-and-stop.html)

```
php test.php start
```

> 最后在`task_queue`和`task_queue_log`表中观察任务的执行情况

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

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

Every ~307 days

Total

2

Last Release

1508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4688b0e744adffc7b6dc00e6407952a6c0cf4efcd5e03ef1ba37af35b8272be0?d=identicon)[ycl123](/maintainers/ycl123)

---

Tags

schedulerqueuescheduling

### Embed Badge

![Health badge](/badges/ycl123-queue/health.svg)

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

###  Alternatives

[php-amqplib/php-amqplib

Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.

4.6k125.3M879](/packages/php-amqplib-php-amqplib)[ramsey/collection

A PHP library for representing and manipulating collections.

1.2k486.0M69](/packages/ramsey-collection)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

91943.6M138](/packages/revolt-event-loop)[queue-interop/queue-interop

Promoting the interoperability of MQs objects. Based on Java JMS

48030.5M87](/packages/queue-interop-queue-interop)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)[phootwork/collection

The phootwork library fills gaps in the php language and provides better solutions than the existing ones php offers.

3924.8M15](/packages/phootwork-collection)

PHPackages © 2026

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