PHPackages                             easyswoole/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. easyswoole/task

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

easyswoole/task
===============

A simple Queue implementation integrated into easySwoole

2.1.2(8mo ago)6128.5k↓21.9%5[1 issues](https://github.com/easy-swoole/task/issues)12Apache-2.0PHPPHP &gt;=8.1

Since Aug 14Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/easy-swoole/task)[ Packagist](https://packagist.org/packages/easyswoole/task)[ RSS](/packages/easyswoole-task/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (18)Used By (12)

Task组件
======

[](#task组件)

出于更加灵活定制化的考虑，EasySwoole实现了一个基于自定义进程的Task组件，用以实现异步任务，并解决：

- 无法投递闭包任务
- 无法在TaskWorker等其他自定义进程继续投递任务
- 实现任务限流与状态监控

> 该组件可以独立使用

安装
--

[](#安装)

```
composer require easyswoole/task

```

示例代码
----

[](#示例代码)

```
use EasySwoole\Task\AbstractInterface\TaskInterface;
use EasySwoole\Task\MessageQueue;
use EasySwoole\Task\Task;

$task = new Task();
//如果需要任务队列，则默认设置进去一个Queue驱动
$queue = new MessageQueue();
$task->getConfig()->setTaskQueue($queue);

class Job implements TaskInterface{

    function run(int $taskId, int $workerIndex)
    {
        var_dump("job rub with id".$taskId);
        return $taskId;
    }

    function onException(\Throwable $throwable, int $taskId, int $workerIndex)
    {
        // TODO: Implement onException() method.
    }
}

$http = new swoole_http_server("127.0.0.1", 9501);
/*
添加服务
*/
$task->attachToServer($http);

$http->on("request", function ($request, $response)use($task){
    if(isset($request->get['sync'])){
        $ret = $task->sync(new Job());
        $response->end("sync result ".$ret);
    }else if(isset($request->get['status'])) {
        var_dump($task->status());
    }else{
        $id = $task->async(new Job());
        $response->end("async id {$id} ");
    }
});

$http->start();
```

### 任务接口

[](#任务接口)

```
class TestTask implements \EasySwoole\Task\AbstractInterface\TaskInterface {

    protected $data = null;

    public function __construct($data = []) {
        // 可通过构造函数传入所需要的数据 可以忽略
        $this->data = $data;
    }

    public function run(int $taskId,int $workerIndex){
        // TODO: Implement run() method.
        return 'success';
    }

    public function onException(\Throwable $throwable,int $taskId,int $workerIndex){
    // TODO: Implement onException() method.
    }
}
/**@var \EasySwoole\Task\Task $task **/
$task->sync(new TestTask([]));
$task->sync(TestTask::class); // 两种方式都可

$task->async(new TestTask([]));
$task->async(TestTask::class,function (){
    // finish 可忽略
});
```

### callable

[](#callable)

```
class TestTask{
    public static function testSync($taskId, $workerIndex){

    }
    public static function testAsync($taskId, $workerIndex){

    }
    public static function testFinish($taskId, $workerIndex){

    }
}
/**@var \EasySwoole\Task\Task $task **/
$task->sync([TestTask::class,'testSync']);
$task->async([TestTask::class,'testAsync'],[TestTask::class,'testFinish']);
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance58

Moderate activity, may be stable

Popularity38

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 86% 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 ~139 days

Recently: every ~438 days

Total

17

Last Release

242d ago

Major Versions

1.1.2 → 2.0.12023-01-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (43 commits)")[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (7 commits)")

---

Tags

easyswoole

### Embed Badge

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

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

###  Alternatives

[easyswoole/easyswoole

An efficient swoole framework

4.8k186.9k50](/packages/easyswoole-easyswoole)[easyswoole/wechat

Coroutine safety WeChat library

8140.8k4](/packages/easyswoole-wechat)[easyswoole/rpc

An efficient swoole framework

7731.6k2](/packages/easyswoole-rpc)[easyswoole/kafka

An efficient swoole framework

4211.1k](/packages/easyswoole-kafka)[easyswoole/actor

easyswoole component

1410.3k](/packages/easyswoole-actor)[easyswoole/words-match

An efficient swoole framework

171.6k3](/packages/easyswoole-words-match)

PHPackages © 2026

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