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 5d 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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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