PHPackages                             out001a/tasque - 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. [Caching](/categories/caching)
4. /
5. out001a/tasque

ActiveLibrary[Caching](/categories/caching)

out001a/tasque
==============

Redis based library for creating background tasks and processing them later.

1.0.1(8y ago)09MITPHPPHP &gt;=7.0

Since Feb 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/out001a/tasque)[ Packagist](https://packagist.org/packages/out001a/tasque)[ Docs](http://www.github.com/out001a/tasque/)[ RSS](/packages/out001a-tasque/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

tasque [![Build Status](https://camo.githubusercontent.com/d8ef5990c785be1f5271f17fb5bbf31c820d13d9b2019a20f49548feb29cffcc/68747470733a2f2f6170692e7472617669732d63692e6f72672f6f7574303031612f7461737175652e706e67)](https://travis-ci.org/out001a/tasque)
============================================================================================================================================================================================================================================================

[](#tasque-)

定时优先级任务处理
---------

[](#定时优先级任务处理)

### 背景

[](#背景)

设计开发这个系统的初衷是为了满足实际业务中对各种异步延时任务的处理需求：

1. 定时
    任务可以在指定的时间自动执行
2. 重试
    任务执行失败时，需要根据指定的规则在特定的时间间隔后重试，直到执行成功或规则结束为止
3. 时间要求是秒级

### 架构

[](#架构)

[![Architecture](https://camo.githubusercontent.com/9d376c0e35e5b845e5f36d9b624123f9754af24ef47cd10045d451585274381d/687474703a2f2f6f6e2d696d672e636f6d2f63686172745f696d6167652f3561613466366132653462303166626463636539363638342e706e67)](https://camo.githubusercontent.com/9d376c0e35e5b845e5f36d9b624123f9754af24ef47cd10045d451585274381d/687474703a2f2f6f6e2d696d672e636f6d2f63686172745f696d6167652f3561613466366132653462303166626463636539363638342e706e67)

### 使用

[](#使用)

- 加载

    1. 执行 `composer require out001a/tasque`， 或者将依赖添加到项目的`composer.json`文件中，

        ```
        {
            "require": {
                "out001a/tasque": "1.*"
            }
        }
        ```

        然后执行 `composer install` 或 `composer update`
    2. 在代码中添加

        ```
        require 'vendor/autoload.php';
        ```
- 示例

    - `tests/bin/test.php`是创建任务并入队的例子
    - `tests/bin/monitor.php`是后台进程分发并处理任务的例子

### 简介

[](#简介)

包含三个相对独立的组件：进程、任务和优先级队列。

1. 进程

    进程组件在`src/Process`目录下，在我之前的一个小项目[php-process](https://github.com/out001a/php-process)的基础上做了些改进，可以满足在生产环境中使用。

    用法如下：

    ```
    // 初始化，自定义一些参数
    Process::init(消息队列对象, 同时存在的最大子进程数, fork子进程的时间间隔);
    Process::register('taskCount', function () {
        // 返回待处理的任务数（随便写个数也可以😄）
        return 1;
    });
    Process::register('dispatch', function() {
        // 分发待处理的任务列表，需要返回array
        return array();
    });
    Process::register('worker',  function() {
        // 注册work进程的业务逻辑
        return do_work();
    });
    // 执行
    Process::handle();
    ```
2. 任务

    在`src/Task`目录下，实现了一个抽象的基础任务类和任务需要重试时应抛出的异常。业务开发时应该基于抽象类实现自己的任务处理逻辑。
3. 优先级队列

    `src/Tasque.php`，基于redis实现了入队、出队等操作。出队按照队列元素的score值从小到大进行。

### 单元测试

[](#单元测试)

```
./vendor/bin/phpunit
```

### TODO

[](#todo)

1. redis断线重连处理
2. 支持平滑重启
3. inotify监控指定文件的变化并自动重启进程
4. 加入日志组件
5. 使用环境变量控制各种参数
6. Web控制台

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

2981d ago

### Community

---

Top Contributors

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

---

Tags

backgrounddelayjobredistasktasque

### Embed Badge

![Health badge](/badges/out001a-tasque/health.svg)

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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