PHPackages                             yiiplus/yii2-websocket - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. yiiplus/yii2-websocket

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

yiiplus/yii2-websocket
======================

使用yii2封装 websocket 扩展

1.0.2(7y ago)212.6k11[1 issues](https://github.com/yiiplus/yii2-websocket/issues)Apache-2.0PHP

Since Dec 25Pushed 7y ago3 watchersCompare

[ Source](https://github.com/yiiplus/yii2-websocket)[ Packagist](https://packagist.org/packages/yiiplus/yii2-websocket)[ RSS](/packages/yiiplus-yii2-websocket/feed)WikiDiscussions master Synced today

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

yii2-websocket
==============

[](#yii2-websocket)

在 yii2 下运行 WebSocket 服务。

[![Latest Stable Version](https://camo.githubusercontent.com/5e51e4fe5862584f7a5897e5f52ce899ea76c1e98078314f70f2b3c80b4f70af/68747470733a2f2f706f7365722e707567782e6f72672f796969706c75732f796969322d776562736f636b65742f762f737461626c65)](https://packagist.org/packages/yiiplus/yii2-websocket)[![Total Downloads](https://camo.githubusercontent.com/eecfdd8a0728177b70ffa4fbbaa500a7983233faef91b02d6d764ed1f4a87baf/68747470733a2f2f706f7365722e707567782e6f72672f796969706c75732f796969322d776562736f636b65742f646f776e6c6f616473)](https://packagist.org/packages/yiiplus/yii2-websocket)[![License](https://camo.githubusercontent.com/f2db28f6686f0edc749d6d6aba1a0c6cf77d52e93f069fb41b5a19b2bccec8ba/68747470733a2f2f706f7365722e707567782e6f72672f796969706c75732f796969322d776562736f636b65742f6c6963656e7365)](https://packagist.org/packages/yiiplus/yii2-websocket)

驱动支持
----

[](#驱动支持)

- [swoole](docs/guide/dirver-swoole.md)
- [workerman](docs/guide/dirver-workerman.md)

安装
--

[](#安装)

安装此扩展程序的首选方法是通过 [composer](http://getcomposer.org/download/).

编辑运行

```
php composer.phar require --prefer-dist yiiplus/yii2-websocket "^1.0.0"
```

或添加配置到项目目录下的`composer.json`文件的 require 部分

```
"yiiplus/yii2-websocket": "^1.0.0"

```

基本使用
----

[](#基本使用)

每个 channel 的功能都需要定义一个单独的类。例如，如果你需要为指定客户端推送一条消息，则该类可能如下所示：

```
namespace xxx\channels;

class PushMessageChannel extends BaseObject implements \yiiplus\websocket\ChannelInterface
{
	public function execute($fd, $data)
	{
		return [
			$fd, // 第一个参数返回客户端ID，多个以数组形式返回
			$data // 第二个参数返回需要返回给客户端的消息
		];
	}

	public function close($fd)
	{
		return;
	}
}
```

以下是从客户端发送消息的方法：

```
Yii::$app->websocket->send(['channel' => 'push-message', 'message' => '用户 xxx 送了一台飞机！']);
```

执行任务的确切方式取决于使用的驱动程序。 大多数驱动程序可以使用控制台命令运行，组件需要在应用程序中注册。

此命令启动一个守护进程，该守护进程维护一个 WebSocket Server，根据客户端发来的数据，处理相关 channel 的任务：

```
yii websocket/start
```

有关驱动程序特定控制台命令及其选项的更多详细信息，请参阅 [文档](docs/guide/)。

###  Health Score

34

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

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 ~17 days

Total

3

Last Release

2608d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b6a2bdc2bf97fc3a04d737a0667adecc36e7dd80feb53b31490362d804df0343?d=identicon)[yiiplus](/maintainers/yiiplus)

---

Top Contributors

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

---

Tags

swoolewebsocketworkermanyii2-extensionwebsocketswooleyii2extension

### Embed Badge

![Health badge](/badges/yiiplus-yii2-websocket/health.svg)

```
[![Health](https://phpackages.com/badges/yiiplus-yii2-websocket/health.svg)](https://phpackages.com/packages/yiiplus-yii2-websocket)
```

###  Alternatives

[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.4M18](/packages/linslin-yii2-curl)[immusen/yii2-swoole-websocket

Websocket server for Yii2 base on swoole 4, Support JSONRPC, Resolve 'method' as a route reflect into controller/action, And support http or redis pub/sub to trigger async task from your web application.

338.8k](/packages/immusen-yii2-swoole-websocket)[joni-jones/yii2-wschat

Online chat based on web sockets and ratchet php

981.3k](/packages/joni-jones-yii2-wschat)[jianyan74/yii2-websocket

yii2 websocket

346.2k](/packages/jianyan74-yii2-websocket)[hiqdev/yii2-hiart

ActiveRecord for API

5951.5k3](/packages/hiqdev-yii2-hiart)

PHPackages © 2026

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