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

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

haozu/delay-queue
=================

Delay queue based on redis

v1.0.1(7y ago)123.4k↓50%8Apache-2.0PHPPHP &gt;=5.6

Since Jun 22Pushed 7y ago2 watchersCompare

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

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

delay-queue
===========

[](#delay-queue)

[![Downloads](https://camo.githubusercontent.com/8ab152ba7939ca27bc29cfb11139a6b193b41a3be6bd769efe951d15e97ba8fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f68616f7a752f64656c61792d71756575652f746f74616c2e737667)](https://github.com/haozu/delay-queue/releases)[![license](https://camo.githubusercontent.com/1c419f89412ea6c234c184ad6d85decb127c18584858d3707ae7d8e2131eccc4/68747470733a2f2f696d672e736869656c64732e696f2f686578706d2f6c2f706c75672e7376673f6d61784167653d32353932303030)](https://github.com/haozu/delay-queue/blob/master/LICENSE)[![Release](https://camo.githubusercontent.com/c04fbae5db9e3951660cb0e5db82453a8a0d3a2c7889688b8b620c9d74924302/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f68616f7a752f64656c61792d71756575652e7376673f6c6162656c3d52656c65617365)](https://github.com/haozu/delay-queue/releases)

基于Redis实现的延迟队列,MsgPack编码数据 参考[有赞延迟队列设计](http://tech.youzan.com/queuing_delay)实现

应用场景
----

[](#应用场景)

- 订单超过30天内未回款，通知处理
- 订单完成后, 如果未评价, 5天后自动好评
- 房租剩余15天, 到期前3天分别发送短信提醒续租等

支付宝异步通知实现
---------

[](#支付宝异步通知实现)

支付宝异步通知时间间隔是如何实现的(通知的间隔频率一般是：2m,10m,10m,1h,2h,6h,15h)

订单支付成功后, 生成通知任务, 放入消息队列中.
任务内容包含Array{0,0,2m,10m,10m,1h,2h,6h,15h}和通知到第几次N(这里N=1, 即第1次).
消费者从队列中取出任务, 根据N取得对应的时间间隔为0, 立即发送通知.

第1次通知失败, N += 1 =&gt; 2
从Array中取得间隔时间为2m, 添加一个延迟时间为2m的任务到延迟队列, 任务内容仍包含Array和N

第2次通知失败, N += 1 =&gt; 3, 取出对应的间隔时间10m, 添加一个任务到延迟队列, 同上
......
第7次通知失败, N += 1 =&gt; 8, 取出对应的间隔时间15h, 添加一个任务到延迟队列, 同上
第8次通知失败, N += 1 =&gt; 9, 取不到间隔时间, 结束通知

实现原理
----

[](#实现原理)

> 利用Redis的有序集合，member为JobId, score为任务执行的时间戳,
> 每秒扫描一次集合，取出执行时间小于等于当前时间的任务.

依赖
--

[](#依赖)

- Redis MsgPack 扩展

下载
--

[](#下载)

[releases](https://github.com/haozu/delay-queue/releases)

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

[](#composer安装)

```
composer require haozu/delay-queue
```

### 添加任务

[](#添加任务)

```
DelayQueue::enqueue('order','Job\\Order\\GetOrder',3,10,['id'=>8008]);
```

### 参数说明

[](#参数说明)

参数名类型含义备注topicstring一组相同类型Job的集合（队列）。供消费者来订阅。jobNamestringjob任务的类名，是延迟队列里的基本单元。与具体的Topic关联在一起。delayintJob需要延迟的时间, 单位：秒ttrintJob执行超时时间, 单位：秒保证job至少被消费一次获取job后超时未处理会重新投入队列argsstringJob的参数内容，供消费者做具体的业务处理，可选参数idstringJob唯一标识需确保JobID唯一 可选参数### 其他例子

[](#其他例子)

- 包装例子 demo/MyDelayQueueDemo.php
- 添加例子 demo/AddDemo.php
- worker例子 demo/BackstageDemo.php.php
- job例子 demo/Job/JobDemo.php
- 测试例子 test/DelayQueueTest.php

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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

Every ~35 days

Total

2

Last Release

2852d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42870dca851bcb8812621a615b31f00b7c26cc5769b5fdc0446db0b4d6b5f51e?d=identicon)[xiexinyang](/maintainers/xiexinyang)

---

Top Contributors

[![xinyangbest](https://avatars.githubusercontent.com/u/26601064?v=4)](https://github.com/xinyangbest "xinyangbest (13 commits)")

---

Tags

delay-queuedelayqueueredis-delay-queuedelay-queuephp-delay-queueredis-delay-queue

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[riki137/multitron

Tool for managing fast both asynchronous and multi-threaded execution of tasks. Focused on performance and pleasant CLI interface.

9016.8k](/packages/riki137-multitron)[hyperf/amqp

A amqplib for hyperf.

241.2M56](/packages/hyperf-amqp)[amphp/cluster

Building multi-core network applications with PHP.

6224.8k1](/packages/amphp-cluster)

PHPackages © 2026

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