PHPackages                             ledc/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ledc/gateway-worker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ledc/gateway-worker
===================

Webman plugin ledc/gateway-worker

v8.3.3(8mo ago)08MITPHPPHP &gt;=8.3

Since Aug 31Pushed 8mo agoCompare

[ Source](https://github.com/ledccn/gateway-worker)[ Packagist](https://packagist.org/packages/ledc/gateway-worker)[ RSS](/packages/ledc-gateway-worker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

webman基础插件之 GatewayWorker
=========================

[](#webman基础插件之-gatewayworker)

简介
--

[](#简介)

基于GatewayWorker的webman基础插件，通过命令行单独启动，重启 `webman` 时，不影响 `GatewayWorker` ，从而与业务解耦。

特性
--

[](#特性)

- 命令行单独启动
- 可单独配置 `Register`、`Gateway`、`BusinessWorker` 各进程是否启动
- 内置通用的 `BusinessWorker` 事件处理类 `\Ledc\GatewayWorker\EventHandler`
- 内置事件枚举 `\Ledc\GatewayWorker\EventEnums`

安装
--

[](#安装)

PHP版本：&gt;=8.3

```
composer require ledc/gateway-worker
```

忽略扩展安装

```
composer require ledc/gateway-worker --ignore-platform-req=ext-posix -W
```

启动
--

[](#启动)

```
php webman gateway:worker start
```

停止
--

[](#停止)

```
php webman gateway:worker stop
```

nginx配置
-------

[](#nginx配置)

```
location /websocket
{
  proxy_pass http://127.0.0.1:这里是Gateway端口;
  proxy_read_timeout 3600;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
  proxy_set_header X-Real-IP $remote_addr;
}

```

唯一配置文件
------

[](#唯一配置文件)

`/config/gateway_worker.php`

配置文件内，有详细的注释，可以帮助您理解各种使用场景下的配置。

最佳实践
----

[](#最佳实践)

通过 `.env` 设置环境变量，以供 `/config/gateway_worker.php` 使用，配置项见下述。

Env环境变量
-------

[](#env环境变量)

```
GATEWAY_SECRET_KEY =
GATEWAY_REGISTER_LISTEN_ADDRESS = 127.0.0.1
GATEWAY_REGISTER_ADDRESS = 127.0.0.1
GATEWAY_REGISTER_PORT = 1236
GATEWAY_LOCAL_IP = 127.0.0.1
GATEWAY_START_PORT = 4000
```

应用场景举例
------

[](#应用场景举例)

[与ThinkPHP等框架结合](https://www.workerman.net/doc/gateway-worker/work-with-other-frameworks.html)

与webman结合
---------

[](#与webman结合)

以提供websocket服务为例：

### 1. 进程启动，返回连接参数

[](#1-进程启动返回连接参数)

进程启动后 `\Ledc\GatewayWorker\EventHandler::onConnect`，服务会返回 `{"event":"init","client_id":"7f0000010fa0000000a2","timestamp":1757583080,"auth":"21826584bdaf086f7e9910baac281eef"}`

### 2. 前端页面转发 上述参数到后端webman接口

[](#2-前端页面转发-上述参数到后端webman接口)

### 3. webman控制器接收到参数，验证用户登陆状态

[](#3-webman控制器接收到参数验证用户登陆状态)

验证通过后，调用 `\Ledc\GatewayWorker\EventHandler::bindUid` 绑定用户。

或者，调用 `\Ledc\GatewayWorker\EventHandler::joinGroup` 把客户端加入群组。

上述，也可同时操作（看业务需要）。

### 4. webman后端注册事件监听

[](#4-webman后端注册事件监听)

#### 配置文件监听

[](#配置文件监听)

编辑 `/config/event.php`，根据需要监听 `\Ledc\GatewayWorker\EventEnums` 内列举的枚举事件

#### 或者在Bootstrap监听

[](#或者在bootstrap监听)

参考 [业务初始化](https://www.workerman.net/doc/webman/others/bootstrap.html)

比如你监听 前端 websocket连接的 `ping` 事件

只需要在 `Bootstrap` 内添加：

```
// 监听ping事件
\Ledc\GatewayWorker\EventEnums::onPing->on(function (string $client_id) {
    // 你的业务代码
});
```

也可以继续注册其他事件的监听，事件调用时机或参数，请参考 `\Ledc\GatewayWorker\EventHandler`。

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance62

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Every ~3 days

Total

4

Last Release

241d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4af14254189bc74029cc40f4206f8006872b0cd092c680201f204a85a490f143?d=identicon)[ledccn](/maintainers/ledccn)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[saithink/saiadmin

webman plugin

2709.9k1](/packages/saithink-saiadmin)[tinywan/exception-handler

webman exception handler plugin

1610.1k2](/packages/tinywan-exception-handler)

PHPackages © 2026

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