PHPackages                             photonphp/swoole-socket.io - 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. photonphp/swoole-socket.io

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

photonphp/swoole-socket.io
==========================

基于Laravel 6和swoole实现socket.io服务端

11PHP

Since Nov 11Pushed 6y ago1 watchersCompare

[ Source](https://github.com/photonphp/swoole-socket.io)[ Packagist](https://packagist.org/packages/photonphp/swoole-socket.io)[ RSS](/packages/photonphp-swoole-socketio/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

swoole-socket.io
================

[](#swoole-socketio)

基于swoole实现socket.io服务端

仅支持 Laravel 6

安装
--

[](#安装)

```
composer require photonphp/swoole-socket.io
```

导入文件
----

[](#导入文件)

```
php artisan vendor:publish --tag=swoole-socket.io
```

命令
--

[](#命令)

```
//启动
php artisan swoole:socket start
//停止
php artisan swoole:socket stop
//重启
php artisan swoole:socket restart
//查看状态
php artisan swoole:socket stats
```

成功启动后如

```
socket.io 服务进程:1	已启动
socket.io 服务进程:2	已启动
socket.io 服务进程:3	已启动
socket.io 服务进程:4	已启动
socket.io 服务进程:5	已启动
socket.io 服务进程:6	已启动
socket.io 服务进程:7	已启动
socket.io 服务进程:8	已启动
socket.io 服务进程:9	已启动
socket.io 服务进程:10	已启动
socket.io 服务进程:11	已启动
socket.io 服务进程:12	已启动
```

查看状态

```
PHP 版本        7.3.11
Swoole 版本     4.4.12
socket.io 状态  启动
socket.io 服务  0.0.0.0
socket.io 端口  9501
累计链接        2
当前链接        2
```

方法
--

[](#方法)

修改 routes/socket.io.php

```
SocketIo::on('connection', function ($socket) {
    echo '连接:' . $socket->id . PHP_EOL;

    $socket->emit('message', ['test' => 'Hello, world!']);//发送消息
    $socket->emitTo('message', ['test' => 'Hello, world!'],$socket->id );// 发送消息给指定用户
    $socket->disconnect();// 关闭当前连接 关通知用户
});
SocketIo::on('disconnect', function ($socket) {
    echo '关闭:' . $socket->id . PHP_EOL;
});
//接收消息
SocketIo::on('message', function ($socket, $data) {
    echo 'message:' . PHP_EOL;
    //发送消息
    $socket->emit('message', ['hello' => 'message received']);
});

SocketIo::on('login','HomeController@login');
//or
SocketIo::on('login',[HomeController::class, 'login']);
```

swoole socket.io 服务进程
---------------------

[](#swoole-socketio-服务进程)

PhotonPHP\\Socket\\Facades\\SocketIo

```
use PhotonPHP\Socket\Facades\SocketIo;

SocketIo::on($event, $callback);// 绑定接收消息
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/photonphp-swoole-socketio/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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