PHPackages                             axguowen/think-gatewayclient - 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. [API Development](/categories/api)
4. /
5. axguowen/think-gatewayclient

ActiveLibrary[API Development](/categories/api)

axguowen/think-gatewayclient
============================

Gateway Client For ThinkPHP

016PHP

Since Apr 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/axguowen/think-gatewayclient)[ Packagist](https://packagist.org/packages/axguowen/think-gatewayclient)[ RSS](/packages/axguowen-think-gatewayclient/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ThinkPHP Gateway Client 客户端
===========================

[](#thinkphp-gateway-client-客户端)

一个简单的ThinkPHP Gateway Client 客户端扩展

安装
--

[](#安装)

```
composer require axguowen/think-gatewayclient

```

配置
--

[](#配置)

首先配置config目录下的gatewayclient.php配置文件。 配置项说明：

```
return [
    // 默认连接本机
    'default' => 'localhost',
    // 连接配置
    'connections' => [
        // 本机连接参数
        'localhost' => [
            // Gateway注册服务地址
            'register_address' => '127.0.0.1:1236',
            // 密钥, 为对应Register服务设置的密钥
            'secret_key' => '',
            // 连接超时时间，单位：秒
            'connect_timeout' => 3,
            // 与Gateway是否是长链接
            'persistent_connection' => false,
        ],
        // 其它主机连接参数
        'other' => [
            // Gateway注册服务地址
            'register_address' => '192.168.0.89:1236',
        ],
    ],
];
```

### 简单使用

[](#简单使用)

```
use \think\facade\GatewayClient;

// GatewayClient支持GatewayWorker中的所有接口(closeCurrentClient和sendToCurrentClient除外)
GatewayClient::sendToAll('{"message": "hello gateway!"}');
```

### 切换连接其它主机

[](#切换连接其它主机)

```
use \think\facade\GatewayClient;
// 连接其它服务器
$gatewayClientOther = GatewayClient::connect('other');
$gatewayClientOther->sendToAll('{"message": "hello gateway!"}');
```

### 动态传入连接的主机参数

[](#动态传入连接的主机参数)

```
use \think\facade\GatewayClient;
// 动态连接
$gatewayClient = GatewayClient::connect([
    // Gateway注册服务地址
    'register_address' => '192.168.0.90:1236',
    // 密钥, 为对应Register服务设置的密钥
    'secret_key' => '',
    // 连接超时时间，单位：秒
    'connect_timeout' => 3,
    // 与Gateway是否是长链接
    'persistent_connection' => false,
]);
$gatewayClient->sendToAll('{"message": "hello gateway!"}');
```

### 其它方法

[](#其它方法)

```
use \think\facade\GatewayClient;
$data = '{"message": "hello gateway!"}';
GatewayClient::sendToAll($data);
GatewayClient::sendToClient($client_id, $data);
GatewayClient::closeClient($client_id);
GatewayClient::isOnline($client_id);
GatewayClient::bindUid($client_id, $uid);
GatewayClient::isUidOnline($uid);
GatewayClient::isUidsOnline($uids);
GatewayClient::getClientIdByUid($uid);
GatewayClient::unbindUid($client_id, $uid);
GatewayClient::sendToUid($uid, $dat);
GatewayClient::joinGroup($client_id, $group);
GatewayClient::sendToGroup($group, $data);
GatewayClient::leaveGroup($client_id, $group);
GatewayClient::getClientCountByGroup($group);
GatewayClient::getClientSessionsByGroup($group);
GatewayClient::getAllClientCount();
GatewayClient::getAllClientSessions();
GatewayClient::setSession($client_id, $session);
GatewayClient::updateSession($client_id, $session);
GatewayClient::getSession($client_id);
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

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://www.gravatar.com/avatar/5bb2b3388238042a25cf42dc44e5ff84adc241510354abae9e91573556753205?d=identicon)[axguowen](/maintainers/axguowen)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/axguowen-think-gatewayclient/health.svg)

```
[![Health](https://phpackages.com/badges/axguowen-think-gatewayclient/health.svg)](https://phpackages.com/packages/axguowen-think-gatewayclient)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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