PHPackages                             81549361/webman-push-server - 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. 81549361/webman-push-server

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

81549361/webman-push-server
===========================

Webman plugin workbunny/webman-push-server

3.0.11(1y ago)0140MITPHPPHP &gt;=8.0

Since Nov 30Pushed 10mo agoCompare

[ Source](https://github.com/81549361/webman-push-server)[ Packagist](https://packagist.org/packages/81549361/webman-push-server)[ RSS](/packages/81549361-webman-push-server/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (69)Used By (0)

[![workbunny](https://camo.githubusercontent.com/e2b1164338390ab45783434659e3e419e0c3b50fbe140c697ba1f82f59015ad6/68747470733a2f2f6368617a366368657a2e636e2f696d616765732f776f726b62756e6e792d6c6f676f2e706e67)](https://camo.githubusercontent.com/e2b1164338390ab45783434659e3e419e0c3b50fbe140c697ba1f82f59015ad6/68747470733a2f2f6368617a366368657a2e636e2f696d616765732f776f726b62756e6e792d6c6f676f2e706e67)

**workbunny/webman-push-server**

**🐇 Webman plugin for push server implementation. 🐇**

 [ ![Build Status](https://github.com/workbunny/webman-push-server/actions/workflows/CI.yml/badge.svg) ](https://github.com/workbunny/webman-push-server/actions?query=branch%3A2.x) [ ![Latest Stable Version](https://camo.githubusercontent.com/f7c52585b5c8fed2e2b547f33ef70ad80d25a22a934a2eb4a5d3e7edaeadda88/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f776f726b62756e6e792f7765626d616e2d707573682d7365727665722f6c6174657374) ](https://github.com/workbunny/webman-push-server/releases) [ ![PHP Version Require](https://camo.githubusercontent.com/8057cea673f17a7b7edf045c71efd905280d0e42d32e2e71d43efe512c281738/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f776f726b62756e6e792f7765626d616e2d707573682d736572766572) ](https://github.com/workbunny/webman-push-server/blob/main/composer.json) [ ![GitHub license](https://camo.githubusercontent.com/e848f186f17ec4546712ac99127f3f2a54467c0e03b002835d1ffcd76ddc4f84/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f6c6963656e73652f776f726b62756e6e792f7765626d616e2d707573682d736572766572) ](https://github.com/workbunny/webman-push-server/blob/main/LICENSE)

当前为2.x版本，[点击跳转1.x文档](https://github.com/workbunny/webman-push-server/blob/1.x/README.md)
----------------------------------------------------------------------------------------

[](#当前为2x版本点击跳转1x文档)

简介
--

[](#简介)

- 本项目的诞生初期是为了实现我司商业化项目中的**在线推送服务**，早期考察了[webman/push](https://www.workerman.net/plugin/2)，对它进行了多进程的实现，并且根据[Pusher-Channel](https://support.pusher.com/hc/en-us/categories/4411973917585-Channels)服务的文档进行了改造， [Pusher-Channel](https://support.pusher.com/hc/en-us/categories/4411973917585-Channels)服务的一比一复刻版本，是一个完整的即时通讯服务；利用该插件可以轻松实现聊天、在线推送等业务服务，也可以利用该插件作为微服务的消息订阅服务； 本插件的商业化项目已于22年初上线稳定运行至今。 该服务是**生产可用**的服务，在商业化项目作为**在线推送服务**和**数字大屏服务**中已稳定运行半年以上。
- 如遇问题，欢迎 **[issue](https://github.com/workbunny/webman-push-server/issues) &amp; PR**；

依赖
--

[](#依赖)

- **php &gt;=8.0**
- **redis &gt;= 6.2**

安装
--

[](#安装)

```
composer require workbunny/webman-push-server

```

简介
--

[](#简介-1)

### 架构设计：

[](#架构设计)

```
                                                     ┌─────────────┐
                                                     | Api-service |
                                                     └─────────────┘
                                                            |
                                   ┌─────────────┐        2 | 3
                             ┌───> | Push-server | ────── ─ · ─        | Channel-server | ─── 1            | Channel-client |
    └────────────────────┘ ──┐     └────────────────┘                       └────────────────┘
                             |     ┌─────────────┐        2 | 3                     ↑
                             └───> | Hook-server | ────── ─ · ─        'workbunny',
    'heartbeat'      => 60,
    'auth'           => 'http://127.0.0.1:8002/subscribe/auth',
    'channel_data'   => []  // channel_data
    'query'          => [], // query
    'context_option' => []
])
// 建立连接
$client->connect();
// 关闭连接
$client->disconnect();
```

#### 2. 订阅/退订

[](#2-订阅退订)

```
use Workbunny\WebmanPushServer\WsClient;
use Workerman\Connection\AsyncTcpConnection;

// 创建连接
$client = WsClient::instance('127.0.0.1:8001', [
    'app_key'        => 'workbunny',
    'heartbeat'      => 60,
    'auth'           => 'http://127.0.0.1:8002/subscribe/auth',
    'channel_data'   => []  // channel_data
    'query'          => [], // query
    'context_option' => []
])

// 订阅一个私有通道，订阅成功后会执行回调函数
$client->subscribe('private-test', function (AsyncTcpConnection $connection, array $data) {
    // 订阅成功后打印
    dump($data);
});
// 订阅一个私有通道，不注册订阅成功后的回调
$client->subscribe('private-test');

// 取消订阅一个私有通道
$client->unsubscribe('private-test', function (AsyncTcpConnection $connection, array $data) {
    // 取消订阅成功后打印
    dump($data);
});
// 取消订阅一个私有通道，不注册订阅成功后的回调
$client->unsubscribe('private-test');

// 取消全部订阅
$client->unsubscribeAll();
```

#### 3. 触发消息

[](#3-触发消息)

```
// 向 private-test 通道发送 client-test 事件消息
$client->trigger('private-test', 'client-test', [
    'message' => 'hello workbunny!'
]);

// 向 presence-test 通道发送 client-test 事件消息
$client->trigger('presence-test', 'client-test', [
    'message' => 'hello workbunny!'
]);

// 事件不带 client- 前缀会抛出RuntimeException
try {
    $client->trigger('presence-test', 'test', [
        'message' => 'hello workbunny!'
    ]);
} catch (RuntimeException $exception){
    dump($exception);
}
```

#### 4. 事件注册回调

[](#4-事件注册回调)

```
use Workerman\Connection\AsyncTcpConnection;

// 注册关注private-test通道的client-test事件
$client->eventOn('private-test', 'client-test', function(AsyncTcpConnection $connection, array $data) {
    // 打印事件数据
    dump($data);
});
// 取消关注private-test通道的client-test事件
$client->eventOff('private-test', 'client-test');

// 获取所有注册事件回调
$client->getEvents();
```

#### 5. 其他

[](#5-其他)

```
// 获取客户端id，当连接创建前该方法返回null
$client->getSocketId();

// 获取已订阅通道，订阅触发前该方法返回空数组
$client->getChannels();

// 发布消息
$client->publish();

// 更多详见 WsClient.php
```

### 服务端使用

[](#服务端使用)

服务端会分别启动一下服务进程：

- push-server
    - 主服务进程，用于监听websocket协议信息
    - 配置位于config/plugin/workbunny/webman-push-server/app.php
    - api-service子服务
        - api子服务，用于提供http-api接口服务
        - 路由配置位于config/plugin/workbunny/webman-push-server/route.php
- hook-server
    - hook多进程消费服务，用于消费事件钩子，进行webhook通知
    - 配置位于config/plugin/workbunny/webman-push-server/app.php

#### 1.HOOK服务

[](#1hook服务)

##### 支持的HOOK事件：

[](#支持的hook事件)

- 通道类型事件
    - channel\_occupied：当通道被建立时，该事件触发
    - channel\_vacated：当通道被销毁时，该事件被触发
- 用户类型事件
    - member\_added：当用户加入通道时，该事件被触发
    - member\_removed：当用户被移除通道时，该事件被触发
- 消息类型事件
    - client\_event：当通道产生客户端消息时，该事件被触发
    - server-event：当通道产生服务端消息（服务端推送消息、服务端回执消息）时，该事件被触发

##### 事件处理器：

[](#事件处理器)

1. Hook服务是多进程消费队列，进程数详见**config/plugin/workbunny/webman-push-server/process.php**；
2. 默认使用webhook方式进行消费通知，详见**WebhookHandler**;
3. 支持自定义消费方式，方法如下：
    - 创建自定义handler类，实现接口**HookHandlerInterface**
    - 将类名添加至配置文件**config/plugin/workbunny/webman-push-server/app.php**的**hook\_handler**中
    - 重启服务

##### 注意事项：

[](#注意事项)

1. 在队列无法发布消息等意外情况下，队列消息会暂时持久化至本地数据库，直到队列恢复后队列消息将自动恢复至队列；
    - 本地数据库默认采用SQLite3，配置详见**config/plugin/workbunny/webman-push-server/database.php**
    - 本地暂存的队列消息会以定时器的方式重载至队列，配置详见**config/plugin/workbunny/webman-push-server/app.php -&gt; hook\_server.requeue\_interval**
2. 队列消息存在一定的pending时间，配置支持设置**pending\_timeout**和**claim\_interval**用于缓解可能存在的消息数据冗余；
    - **config/plugin/workbunny/webman-push-server/app.php -&gt; hook\_server.claim\_interval**用于创建消息回收定时器来进行冗余消息回收
    - **config/plugin/workbunny/webman-push-server/app.php -&gt; hook\_server.pending\_timeout**用于确定需要被回收的冗余消息，pending时间达到该配置的消息将会被消息回收定时器回收

#### 2.API子服务

[](#2api子服务)

API子服务提供REST风格的http-APIs，接口内容与 [pusher-channel-api](https://pusher.com/docs/channels/library_auth_reference/rest-api/) 基本保持一致；

##### 支持的http-api接口：

[](#支持的http-api接口)

methodurl描述POST/apps/\[app\_id\]/events[对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#post-event-trigger-an-event)POST/apps/\[app\_id\]/batch\_events[对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#post-batch-events-trigger-multiple-events)GET/apps/\[app\_id\]/channels[对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#get-channels-fetch-info-for-multiple-channels)GET/apps/\[app\_id\]/channels/\[channel\_name\][对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#get-channel-fetch-info-for-one-channel)POST/apps/\[app\_id\]/users/\[user\_id\]/terminate\_connections[对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#post-terminate-user-connections)GET/apps/\[app\_id\]/channels/\[channel\_name\]/users[对应的pusher文档地址](https://pusher.com/docs/channels/library_auth_reference/rest-api/#get-users)##### API客户端

[](#api客户端)

1. 使用pusher提供的api客户端 **【不建议使用，客户端请求没有使用keep-alive】**

    ```
    composer require pusher/pusher-php-server

    ```
2. 或者使用\\Workbunny\\WebmanPushServer\\ApiClient **【建议使用】**

**服务端推送（PHP示例）：**

```
use Workbunny\WebmanPushServer\ApiClient;

try {
    $pusher = new ApiClient(
        'APP_KEY',
        'APP_SECRET',
        'APP_ID',
        [
            'host'       =>"http://127.0.0.1:8001",
            'timeout'    => 60,
            'keep-alive' => true
        ]
    );
    $pusher->trigger(
        // 频道（channel）支持多个通道
        ["private-d"],
        // 事件
        "client-a",
        // 消息体
        [
            'message' => 'hello workbunny!'
        ],
        // query
        []
    );
} catch (GuzzleException|ApiErrorException|PusherException $e) {
    dump($e);
}
```

### 其他

[](#其他)

#### wss代理(SSL)

[](#wss代理ssl)

https下无法使用ws连接，需要使用wss连接。这种情况可以使用nginx代理wss，配置类似如下：

```
server {
# .... 这里省略了其它配置 ...

    location /app
    {
        proxy_pass http://127.0.0.1:3131;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header X-Real-IP $remote_addr;
    }
}

```

重启nginx后，使用以下方式连接服务端

```
var connection = new Push({
    url: 'wss://example.com',
    app_key: ''
});
```

**Tips：wss开头，不写端口，必须使用ssl证书对应的域名连接**

#### 其他客户端地址

[](#其他客户端地址)

兼容pusher，其他语言(Java Swift .NET Objective-C Unity Flutter Android IOS AngularJS等)客户端地址下载地址： [https://pusher.com/docs/channels/channels\_libraries/libraries/](https://pusher.com/docs/channels/channels_libraries/libraries/)

优化
--

[](#优化)

### todo

[](#todo)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance51

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~14 days

Recently: every ~42 days

Total

66

Last Release

309d ago

Major Versions

1.2.10 → 2.0.0-beta.12024-04-02

1.2.11 → 2.0.32024-04-09

1.3.0 → 2.0.42024-04-12

2.0.7 → 3.0.0-beta.12024-07-04

2.0.8 → 3.0.12024-07-19

PHP version history (2 changes)0.0.1PHP &gt;=7.4

2.0.0-beta.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/998557c974320089745025b15a94b6ad12cabb74909e5b64f9615e29f0099560?d=identicon)[81549361](/maintainers/81549361)

---

Top Contributors

[![chaz6chez](https://avatars.githubusercontent.com/u/22535862?v=4)](https://github.com/chaz6chez "chaz6chez (168 commits)")[![sunsgneayo](https://avatars.githubusercontent.com/u/51745500?v=4)](https://github.com/sunsgneayo "sunsgneayo (4 commits)")[![81549361](https://avatars.githubusercontent.com/u/7599454?v=4)](https://github.com/81549361 "81549361 (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/81549361-webman-push-server/health.svg)

```
[![Health](https://phpackages.com/badges/81549361-webman-push-server/health.svg)](https://phpackages.com/packages/81549361-webman-push-server)
```

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[hanson/vbot

高度自定义的微信机器人，能够实现群控制，自动回复，消息转发，防撤回，留言统计等功能

4.4k14.4k12](/packages/hanson-vbot)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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