PHPackages                             lynnfly/hyperf-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. lynnfly/hyperf-gateway-worker

ActiveLibrary

lynnfly/hyperf-gateway-worker
=============================

1.0.1(11mo ago)3146MITPHPPHP &gt;=8.0

Since Mar 19Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/imlinfly/hyperf-gateway-worker)[ Packagist](https://packagist.org/packages/lynnfly/hyperf-gateway-worker)[ RSS](/packages/lynnfly-hyperf-gateway-worker/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

### 让GatewayWorker支持在Hyperf Swoole环境下运行

[](#让gatewayworker支持在hyperf-swoole环境下运行)

用到的组件
-----

[](#用到的组件)

1. [yurunsoft/workerman-gateway-sdk](https://github.com/Yurunsoft/workerman-gateway-sdk)
2. [workerman/gateway-worker](https://github.com/walkor/GatewayWorker)

### 安装

[](#安装)

```
composer require lynnfly/hyperf-gateway-worker
```

### 发布配置

[](#发布配置)

```
php bin/hyperf.php vendor:publish lynnfly/hyperf-gateway-worker
```

### 查看命令帮助

[](#查看命令帮助)

```
php bin/hyperf.php gateway:worker --help

Description:
  Gateway Worker Service.

Usage:
  gateway:worker [options] [--] []

Arguments:
  action                          start|stop|restart|reload|status|connections [default: "start"]

Options:
  -r, --register                  Enable register service
  -g, --gateway                   Enable gateway service
  -d, --daemon                    Run the worker in daemon mode.
```

### 启动服务

[](#启动服务)

该命令只用于开发环境使用，生产环境建议网关、注册中心进程与业务分开部署

具体请参考GatewayWorker官方文档。

```
php bin/hyperf.php gateway:worker -r -g start
```

#### 业务代码示例

[](#业务代码示例)

1. 修改gateway\_worker.php配置文件中的event\_handler配置项为你的业务类

```
return [
    // 业务进程
    'business' => [
        // 是否启用
        'enable' => true,
        // ...
        // 事件处理类
        'event_handler' => LynnFly\GatewayWorker\EventHandler::class,
        // ...
    ],
    // ...
];
```

2. 业务事件处理类示例

- onWebSocketConnect: WebSocket连接事件
- onConnect: 客户端连接事件
- onMessage: 客户端消息事件
- onClose: 客户端关闭事件
- onException: 异常事件

GatewayWorker的事件处理类必须是静态方法

请勿覆盖$_SESSION变量，否则可能会导致数据不一致，建议使用GatewaySession类

```
class EventHandler
{
    public static function onWebSocketConnect(string $clientId, array $body): void
    {
        var_dump(__METHOD__);
        echo "onWebSocketConnect clientId: $clientId\n";
    }

    public static function onConnect(string $clientId): void
    {
        var_dump(__METHOD__);
        echo "onConnect clientId: $clientId\n";

        $uid = mt_rand(1111, 9999);
        GatewaySession::set('uid', $uid); // or $_SESSION['uid'] = $uid;

        Gateway::sendToCurrentClient("Hello $uid, clientId: $clientId\n");
    }

    public static function onMessage(string $clientId, string $body): void
    {
        var_dump(__METHOD__);
        echo "onMessage clientId: $clientId, body: $body\n";

        $uid1 = GatewaySession::get('uid');
        $uid2 = $_SESSION['uid'] ?? null;

        Gateway::sendToCurrentClient("Hi，$uid1:$uid2\nReceived: $body\n");
    }

    public static function onClose(string $clientId): void
    {
        var_dump(__METHOD__);
        echo "onClose clientId: $clientId\n";
    }

    public static function onException(Throwable $throwable): void
    {
        var_dump(__METHOD__, $throwable->getMessage());
    }
}
```

###  Health Score

31

—

LowBetter than 71% of packages

Maintenance52

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

2

Last Release

331d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3547ea3eaacfdb9b1bf6fd3d03fde2e1324ae00679d67542d12b126e7019274b?d=identicon)[linfcom](/maintainers/linfcom)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[mineadmin/mineadmin

Quickly build a background management system for web applications

1.2k2.0k](/packages/mineadmin-mineadmin)[hyperf/swow-skeleton

A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.

494.5k](/packages/hyperf-swow-skeleton)[hyperf/xxl-job-incubator

php hyperf xxljob

4630.4k2](/packages/hyperf-xxl-job-incubator)[xmo/mine-core

mineadmin core package

1683.1k1](/packages/xmo-mine-core)

PHPackages © 2026

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