PHPackages                             reactphp-x/gateway-worker - 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. reactphp-x/gateway-worker

ActiveLibrary

reactphp-x/gateway-worker
=========================

Distributed long-connection gateway for reactphp-x/worker (TCP + WebSocket)

04↓75%PHP

Since Jul 13Pushed 1mo agoCompare

[ Source](https://github.com/reactphp-x/gateway-worker)[ Packagist](https://packagist.org/packages/reactphp-x/gateway-worker)[ RSS](/packages/reactphp-x-gateway-worker/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

reactphp-x/gateway-worker
=========================

[](#reactphp-xgateway-worker)

基于 [reactphp-x/worker](https://github.com/reactphp-x/worker) 的分布式长连接 GatewayWorker 实现，架构参考 Workerman GatewayWorker，支持 **TCP** 与 **WebSocket**（WebSocket 使用 [reactphp-x/websocket-middleware](https://github.com/reactphp-x/websocket-middleware)）。

架构
--

[](#架构)

```
Client (TCP/WebSocket)
        ↓
    Gateway  ←→  Register  ←→  BusinessWorker
        ↓                            ↓
   转发连接事件                  Events 业务逻辑

```

- **Register**：服务注册中心，协调 Gateway 与 BusinessWorker 地址发现
- **Gateway**：接受客户端长连接，通过二进制 GatewayProtocol 转发给 BusinessWorker
- **BusinessWorker**：处理 `onConnect` / `onMessage` / `onClose` 业务逻辑

安装
--

[](#安装)

```
composer install
```

运行示例
----

[](#运行示例)

```
cd examples
php start.php start
```

默认端口：

服务地址Register127.0.0.1:1238（仅内网）Gateway TCP0.0.0.0:8282Gateway WebSocketws://0.0.0.0:8283/wsBusinessWorker4 进程### TCP 测试

[](#tcp-测试)

```
telnet 127.0.0.1 8282
```

### WebSocket 测试

[](#websocket-测试)

```

  var conn = new WebSocket('ws://127.0.0.1:8283/ws');
  conn.onopen = () => conn.send('Hello!');
  conn.onmessage = (e) => console.log(e.data);

```

### WebSocket 二进制帧

[](#websocket-二进制帧)

BusinessWorker 发送非 JSON 载荷（如 Needle Engine `SyncedTransform` 的 FlatBuffer `STRS` 消息）时，须将 `$raw` 设为 `true`：

```
// 单播二进制
Gateway::sendToClient($clientId, $binaryPayload, raw: true);

// 组播二进制（第四个参数）
Gateway::sendToGroup($group, $binaryPayload, $excludeClientId, raw: true);
```

Gateway 收到 `FLAG_NOT_CALL_ENCODE` 后，会以 **WebSocket binary frame**（opcode `0x2`）发给浏览器，而不是 text frame。若以 text frame 发送非 UTF-8 数据，浏览器会报错并断开连接。

自定义应用
-----

[](#自定义应用)

参考 `examples/Applications/YourApp/`：

- `start_register.php` — 注册中心
- `start_gateway_tcp.php` — TCP Gateway
- `start_gateway_websocket.php` — WebSocket Gateway
- `start_businessworker.php` — 业务 Worker
- `Events.php` — 业务回调

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance60

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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/76907477?v=4)[wpjscc](/maintainers/wpjscc)[@wpjscc](https://github.com/wpjscc)

---

Top Contributors

[![wpjscc](https://avatars.githubusercontent.com/u/76907477?v=4)](https://github.com/wpjscc "wpjscc (10 commits)")

### Embed Badge

![Health badge](/badges/reactphp-x-gateway-worker/health.svg)

```
[![Health](https://phpackages.com/badges/reactphp-x-gateway-worker/health.svg)](https://phpackages.com/packages/reactphp-x-gateway-worker)
```

PHPackages © 2026

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