PHPackages                             xiaochengfu/swoole-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. xiaochengfu/swoole-websocket

ActivePhp-extension

xiaochengfu/swoole-websocket
============================

Swoole 扩展，整合websocket通信、服务端实时推送等服务

v1.0(6y ago)5714BSD-3-ClausePHP

Since Dec 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xiaochengfu/websocket-swoole)[ Packagist](https://packagist.org/packages/xiaochengfu/swoole-websocket)[ RSS](/packages/xiaochengfu-swoole-websocket/feed)WikiDiscussions master Synced 2mo ago

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

websocket-Swoole php框架扩展
========================

[](#websocket-swoole-php框架扩展)

> ## 扩展说明
>
> [](#扩展说明)

基于swoole开发的websocket实时推送、主动推送、长连接扩展，应用于php的各类框架，如thinkphp,yii2,laravel等

> ## 如何使用
>
> [](#如何使用)

安装
--

[](#安装)

```
composer require xiaochengfu/swoole-websocket
```

配置
--

[](#配置)

1.将params\_swoole.php.default配置文件放到你框架配置文件夹下 推荐放到config下：

```
laravel、thinkphp5/6放到config目录下

yii2放到common/config目录下
```

2.修改配置文件

如何修改，配置文件中有具体说明

启动
--

[](#启动)

根据每个框架的自定义命令，设置对应的指令即可，以启动为例

```
$setting = config('params.swoole');//框架获取配置的方法，各有不同

$swoole = new SwooleService($setting);
$swoole->serviceStart();
```

扩展支持

a.启动服务 serviceStart

b.查看服务状态 serviceStats

c.查看进程列表 serviceList

d.停止服务 serviceStop

场景测试
----

[](#场景测试)

1.连接socket

访问`http://www.websocket-test.com`，输入ip:9512，进行连接测试

2.测试推送

推送通过http请求触发，在你要触发推送的action中，添加

```
$swoole = new \xiaochengfu\swoole\Swoole(config('params.swoole'));
$swoole->pushMsg(1,['hello','world']);

//注意pushMsg($fd,$data)
//fd 这里可用刚连接的客户端1
//data 类型为数组
```

正确的话，你将在刚连接的浏览器客户端中接收到推送消息

3. 测试实时消息通信

这里采用callback回调的方式，可灵活的嵌入逻辑，只需要把`SwooleCallback.php`文件放到vendor外的任何地方，通过修改命名空间来访问，这里仅把SwooleCallback.php文件当作测试回调文件!

客户端发送消息格式如下：

```
{"data":{"namespace":"xiaochengfu\\swoole\\SwooleCallback","function":"test","params":{"a":1}}}
```

\---敲黑板---

a.发送的消息必须为字符串

b.格式说明

`namespace` 为回调文件的名字空间

`function` 为回调文件内的方法，必须为静态方法

`params` 为方法的参数

正确的话，socket客户端将立即收到服务端返回的消息

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

2323d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a10742992d52a3b211ea0790e1db0e1eb0c4230296b34b290457fa520a8d4ef?d=identicon)[xiaochengfu](/maintainers/xiaochengfu)

---

Top Contributors

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

---

Tags

laravel-websocketphp-websocketphp-websocket-serverthinkphp-websocketyii2-websocketlaravelswooleyii2extensionthinkphp5laravel-swooleyii2-swoolethinkphp5-swoole

### Embed Badge

![Health badge](/badges/xiaochengfu-swoole-websocket/health.svg)

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

###  Alternatives

[feehi/yii2-swoole

yii2 swoole,让yii2跑在swoole上

3448.3k1](/packages/feehi-yii2-swoole)[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)

PHPackages © 2026

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