PHPackages                             wtwt/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. wtwt/yii2-websocket

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

wtwt/yii2-websocket
===================

使用yii2封装 websocket 扩展

1.0.0(1y ago)020Apache-2.0PHP

Since May 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/skltzjt/yii2-websocket)[ Packagist](https://packagist.org/packages/wtwt/yii2-websocket)[ RSS](/packages/wtwt-yii2-websocket/feed)WikiDiscussions main Synced 1mo ago

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

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

[](#yii2-websocket)

在 yii2 下运行 WebSocket 服务。

[![Latest Stable Version](https://camo.githubusercontent.com/c0f2ba4440c95f42f9ce1c554217c731369dd0f8c484aaa0c5748449a46aa339/68747470733a2f2f706f7365722e707567782e6f72672f777477742f796969322d776562736f636b65742f762f737461626c65)](https://packagist.org/packages/wtwt/yii2-websocket)[![Total Downloads](https://camo.githubusercontent.com/75d965cadbb7477067355061e5ae925cae855df05e31ce6a128fab0bee1c6526/68747470733a2f2f706f7365722e707567782e6f72672f777477742f796969322d776562736f636b65742f646f776e6c6f616473)](https://packagist.org/packages/wtwt/yii2-websocket)[![License](https://camo.githubusercontent.com/058430a96f672b1187ef1fc66ef3c85552342c43284f4723edd4f5bbbf69888f/68747470733a2f2f706f7365722e707567782e6f72672f777477742f796969322d776562736f636b65742f6c6963656e7365)](https://packagist.org/packages/wtwt/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 wtwt/yii2-websocket "^1.0.0"
```

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

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

```

基本使用
----

[](#基本使用)

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

```
namespace xxx\channels;

class PushMessageChannel extends BaseObject implements \wtwt\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

23

—

LowBetter than 27% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

720d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/259e3aac0d9cb05c15ba84f0220007b1550121b8cae9d45d1ae1e1b4fccb0eee?d=identicon)[skltzjt](/maintainers/skltzjt)

---

Top Contributors

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

---

Tags

websocketswooleyii2extension

### Embed Badge

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

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

###  Alternatives

[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.5M20](/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)[yiiplus/yii2-websocket

使用yii2封装 websocket 扩展

212.6k](/packages/yiiplus-yii2-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.2k1](/packages/jianyan74-yii2-websocket)

PHPackages © 2026

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