PHPackages                             yuanling/channel - 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. yuanling/channel

ActiveLibrary

yuanling/channel
================

v1.0.6(5y ago)04MITPHP

Since Sep 30Pushed 5y agoCompare

[ Source](https://github.com/LaneHub/channel)[ Packagist](https://packagist.org/packages/yuanling/channel)[ Docs](http://www.workerman.net)[ RSS](/packages/yuanling-channel/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Channel
=======

[](#channel)

基于订阅的多进程通讯组件，用于workerman进程间通讯或者服务器集群通讯，类似redis订阅发布机制。基于workerman开发。

Channel 提供两种通讯形式，分别是发布订阅的事件机制和消息队列机制。

它们的主要区别是：

- 事件机制是消息发出后，所有订阅该事件的客户端都能收到消息。
- 消息队列机制是消息发出后，所有订阅该消息的客户端只有一个会收到消息，如果客户端忙消息会进行排队直到有客户端闲置后重新取到消息。
- 需要注意的是 Channel 只是提供一种通讯方式，本身并不提供消息确认、重试、延迟、持久化等功能，请根据实际情况合理使用。

手册地址
====

[](#手册地址)

[Channel手册](http://doc.workerman.net/components/channel.html)

服务端
===

[](#服务端)

```
use Workerman\Worker;

$channel_server = new Channel\Server('0.0.0.0', 2206);

if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}
```

客户端
===

[](#客户端)

```
use Workerman\Worker;

$worker = new Worker(....);
$worker->onWorkerStart = function()
{
    // Channel客户端连接到Channel服务端
    Channel\Client::connect('', 2206);
    // 要订阅的事件名称（名称可以为任意的数字和字符串组合）
    $event_name = 'event_xxxx';
    // 订阅某个自定义事件并注册回调，收到事件后会自动触发此回调
    Channel\Client::on($event_name, function($event_data){
        var_dump($event_data);
    });
};
$worker->onMessage = function($connection, $data)
{
    // 要发布的事件名称
    $event_name = 'event_xxxx';
    // 事件数据（数据格式可以为数字、字符串、数组），会传递给客户端回调函数作为参数
    $event_data = array('some data.', 'some data..');
    // 发布某个自定义事件，订阅这个事件的客户端会收到事件数据，并触发客户端对应的事件回调
    Channel\Client::publish($event_name, $event_data);
};

if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}
```

消息队列示例
------

[](#消息队列示例)

```
use Workerman\Worker;
use Workerman\Timer;

$worker = new Worker();
$worker->name = 'Producer';
$worker->onWorkerStart = function()
{
    Client::connect();

    $count = 0;
    Timer::add(1, function() {
        Client::enqueue('queue', 'Hello World '.time());
    });
};

$mq = new Worker();
$mq->name = 'Consumer';
$mq->count = 4;
$mq->onWorkerStart = function($worker) {
    Client::connect();

    //订阅消息 queue
    Client::watch('queue', function($data) use ($worker) {
        echo "Worker {$worker->id} get queue: $data\n";
    });

    //10 秒后取消订阅该消息
    Timer::add(10, function() {
        Client::unwatch('queue');
    }, [], false);
};

Worker::runAll();
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 86.1% 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 ~307 days

Recently: every ~424 days

Total

7

Last Release

2036d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ee78d404d2ec853f98a0fecf3d1ee71dba5ba98a6e4513a2592fd98db14c0d41?d=identicon)[yuanling](/maintainers/yuanling)

---

Top Contributors

[![walkor](https://avatars.githubusercontent.com/u/6073368?v=4)](https://github.com/walkor "walkor (31 commits)")[![xpader](https://avatars.githubusercontent.com/u/8629617?v=4)](https://github.com/xpader "xpader (3 commits)")[![xeden3](https://avatars.githubusercontent.com/u/38025067?v=4)](https://github.com/xeden3 "xeden3 (1 commits)")[![xuedhh](https://avatars.githubusercontent.com/u/27466306?v=4)](https://github.com/xuedhh "xuedhh (1 commits)")

### Embed Badge

![Health badge](/badges/yuanling-channel/health.svg)

```
[![Health](https://phpackages.com/badges/yuanling-channel/health.svg)](https://phpackages.com/packages/yuanling-channel)
```

###  Alternatives

[workerman/phpsocket.io

A server side alternative implementation of socket.io in PHP based on Workerman

2.3k578.6k16](/packages/workerman-phpsocketio)[workerman/gateway-worker

1.0k643.4k74](/packages/workerman-gateway-worker)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[workerman/webman-framework

High performance HTTP Service Framework.

149314.9k256](/packages/workerman-webman-framework)[joanhey/adapterman

Use any framework and application with Workerman.

85255.9k1](/packages/joanhey-adapterman)[workerman/channel

146849.0k19](/packages/workerman-channel)

PHPackages © 2026

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