PHPackages                             mevyen/yii2-swoole-async - 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. mevyen/yii2-swoole-async

ActiveYii2-extension[Queues &amp; Workers](/categories/queues)

mevyen/yii2-swoole-async
========================

yii2异步任务扩展

1.1.0(8y ago)4933910[1 issues](https://github.com/mevyen/yii2-swoole-async/issues)BSD-4-ClausePHP

Since Sep 30Pushed 8y ago4 watchersCompare

[ Source](https://github.com/mevyen/yii2-swoole-async)[ Packagist](https://packagist.org/packages/mevyen/yii2-swoole-async)[ RSS](/packages/mevyen-yii2-swoole-async/feed)WikiDiscussions master Synced yesterday

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

yii2 Swoole Async
=================

[](#yii2-swoole-async)

yii2异步任务扩展:基于swoole和yii2-console的异步任务实现，配置简洁，与Yii2无缝集成，只需要安装swoole扩展即可使用

swoole版本要求：&gt;=1.8.1

实现原理
----

[](#实现原理)

1、客户端发送异步console任务执行请求

2、服务端响应请求，并立即返回

3、服务端发起task执行任务，执行请求携带的所有任务

适用场景
----

[](#适用场景)

需要客户端触发的耗时请求，客户端无需等待返回结果

安装
--

[](#安装)

```
composer require mevyen/yii2-swoole-async "dev-master"

```

如何使用
----

[](#如何使用)

1、新增配置文件params\_swoole.php

```
return [
    'swooleAsync' => [
		'host'             => '127.0.0.1', 		//服务启动IP
		'port'             => '9512',      		//服务启动端口
		'process_name'     => 'swooleServ',		//服务进程名
		'open_tcp_nodelay' => '1',         		//启用open_tcp_nodelay
		'daemonize'        => '1',				//守护进程化
		'worker_num'       => '2',				//work进程数目
		'task_worker_num'  => '2',				//task进程的数量
		'task_max_request' => '10000',			//work进程最大处理的请求数
		'task_tmpdir'      => '/tmp/task',		 //设置task的数据临时目录
		'log_file'         => '/tmp/log/http.log', //指定swoole错误日志文件
		'client_timeout'   => '20',				 //client链接服务器时超时时间(s)
		'pidfile'          => '/tmp/y.pid', 		 //服务启动进程id文件保存位置

		//--以上配置项均来自swoole-server的同名配置，可随意参考swoole-server配置说明自主增删--
		'log_size'         => 204800000, 			 //运行时日志 单个文件大小
		'log_dir'          => '/tmp/log',			 //运行时日志 存放目录
	]
];
```

2、在console主配置文件(main.php)中增加controllerMap

```
'controllerMap' => [
    'swooleasync' => [
        'class' => 'mevyen\swooleAsync\SwooleAsyncController',
    ],
],
```

3、在站点主配置文件(main.php)中增加components

```
'components' => [
    'swooleasync' => [
        'class' => 'mevyen\swooleAsync\SwooleAsyncComponent',
    ]
]
```

4、服务管理

```
//启动
/path/to/yii/application/yii swooleasync/run start

//重启
/path/to/yii/application/yii swooleasync/run restart

//停止
/path/to/yii/application/yii swooleasync/run stop

//查看状态
/path/to/yii/application/yii swooleasync/run stats

//查看进程列表
/path/to/yii/application/yii swooleasync/run list
```

5、执行任务

```
namespace console\controllers;
use yii\console\Controller;

class TestController extends Controller
{
	public function actionSwooleasync(){
		$data = [
			"data":[
				[
					"a" => "test/mail",
					"p" => ["测试邮件1","测试邮件2"]
				],
				...
			],
			"finish" => [
				[
					"a" => "test/mail",
					"p" => ["测试邮件回调1","测试邮件回调2"]
				],
				...
			]
		];
		\Yii::$app->swooleasync->async(json_encode($data));
	}

	public function actionMail($a='',$b=''){
		echo $a.'-'.$b;
	}
}
```

6、无人值守

服务启动脚本自带服务检测功能，因此可以将启动脚本配置为crontab用以自动保活服务

```
* * * * * /path/to/yii/application/yii swooleasync/run start >> /var/log/console-app.log 2>&1
```

7、demo使用方法

将站点目录指向/demo/test/backend/web 即可

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

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

Every ~298 days

Total

2

Last Release

3263d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5382766?v=4)[mevyen](/maintainers/mevyen)[@mevyen](https://github.com/mevyen)

---

Top Contributors

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

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/mevyen-yii2-swoole-async/health.svg)

```
[![Health](https://phpackages.com/badges/mevyen-yii2-swoole-async/health.svg)](https://phpackages.com/packages/mevyen-yii2-swoole-async)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[trntv/yii2-command-bus

Yii2 Command Bus extension

57660.0k8](/packages/trntv-yii2-command-bus)[mikemadisonweb/yii2-rabbitmq

Wrapper based on php-amqplib to incorporate messaging in your Yii2 application via RabbitMQ. Inspired by RabbitMqBundle for Symfony 2, really awesome package.

72269.0k1](/packages/mikemadisonweb-yii2-rabbitmq)[ignatenkovnikita/yii2-queuemanager

Yii2 Queue Manager

2062.9k2](/packages/ignatenkovnikita-yii2-queuemanager)

PHPackages © 2026

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