PHPackages                             lactone/laravel-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. lactone/laravel-websocket

ActiveLibrary[HTTP &amp; Networking](/categories/http)

lactone/laravel-websocket
=========================

基于laravel+swoole的webSocket开发库

V0.1.3(7y ago)351486MITPHPPHP &gt;=5.5.9

Since Jun 11Pushed 7y ago2 watchersCompare

[ Source](https://github.com/wan3574489/laravel-websocket)[ Packagist](https://packagist.org/packages/lactone/laravel-websocket)[ RSS](/packages/lactone-laravel-websocket/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

laravel-websocket
=================

[](#laravel-websocket)

基于 laravel + swoole +redis的WebSocket开发库。适合开发中小型webSocket程序。

无需关注webSocket的细节，专注业务。

可同步、异步处理请求，发送数据。

安装方法
----

[](#安装方法)

1. 安装laravel.
2. 添加websocket库: composer require lactone/laravel-websocket
3. 添加laravel command类，继承 webSocket\\Commands\\WebSocketCommand.

Demo
----

[](#demo)

在目录/demo/laravel中是一个简单的Demo程序。

### 使用方法

[](#使用方法)

1. 将Demo目录中的文件覆盖到laravel程序中。
2. 配置redis。
3. 打开app/config/app.php,将默认的Redis服务提供器修改为websocket的Redis服务提供器，将Illuminate\\Redis\\RedisServiceProvider替换为\\webSocket\\Redis\\RedisServiceProvider
4. 打开app/config/websocket.php 文件，修改websocket的监听ip、端口和工作进程数量。
5. 命令行执行:**php artisan Chat:Start** 开启websocket服务。

### 文件说明

[](#文件说明)

```
App\Console\Commands\ChatWebSocketCommand.php 负责绑定启动命令、设置websocket的配置和绑定webSocket处理程序。

App\Server\Chat\ChatHandle.php 负责处理ws业务。当用户发送消息:{type:$type,data:$data}给服务器的时候，系统会自动调用message_$type方法。

public/js/push.js 客户端发送消息程序

```

基本概念
----

[](#基本概念)

当客户端与服务端建立webSocket连接后，服务端会生成一个fd,该fd表示当前链接，通过该fd服务端可以发送消息给客户端。

### 数据交互

[](#数据交互)

```
客户端发送给服务端结构如下：{type:type,data:data}
其中如果type为login,服务端接受程序信息后会调用message_login方法，处理信息。

```

### 常用API

[](#常用api)

#### webSocket\\Service\\PushService

[](#websocketservicepushservice)

```
PushService::pushToAllAsync($data) 发送信息给所有客户端
PushService::pushToFdAsync($fd,$data) 发送消息给某个客户端
PushService::pushToAllOutMeAsync($fd,$data) 发送消息给除开fd的其他客户端
PushService::getAllFdsFromStore() 获取所有在线的链接标识
PushService::isLive($fd) 客户端是否在线
PushService::success($action,$message = array()) 反馈成功的数据结构
PushService::error($action,$message = array()) 反馈失败的数据结构

```

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

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

Recently: every ~132 days

Total

6

Last Release

2725d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelwebsocketswoole

### Embed Badge

![Health badge](/badges/lactone-laravel-websocket/health.svg)

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

###  Alternatives

[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k676.0k10](/packages/hhxsv5-laravel-s)[denis660/laravel-centrifugo

Centrifugo broadcaster for laravel

113164.7k](/packages/denis660-laravel-centrifugo)[huang-yi/shadowfax

Run Laravel on Swoole.

3521.7k](/packages/huang-yi-shadowfax)[basement-chat/basement-chat

Add a real-time chat widget to your Laravel application.

4983.9k](/packages/basement-chat-basement-chat)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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