PHPackages                             rasuvaeff/yii3-centrifugo - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. rasuvaeff/yii3-centrifugo

ActiveLibrary[HTTP &amp; Networking](/categories/http)

rasuvaeff/yii3-centrifugo
=========================

Centrifugo v6 integration for Yii3: server API client, JWT token issuer, and PSR-15 proxy event handlers

v1.0.0(today)00BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jun 27Pushed todayCompare

[ Source](https://github.com/rasuvaeff/yii3-centrifugo)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-centrifugo)[ Docs](https://github.com/rasuvaeff/yii3-centrifugo)[ RSS](/packages/rasuvaeff-yii3-centrifugo/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (15)Versions (2)Used By (0)

rasuvaeff/yii3-centrifugo
=========================

[](#rasuvaeffyii3-centrifugo)

[![Stable Version](https://camo.githubusercontent.com/9d98fc20334383d502ecd60dfcaf4678ab2fda6e65e5c487b45cd60bd51a146a/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d63656e7472696675676f2f762f737461626c65)](https://packagist.org/packages/rasuvaeff/yii3-centrifugo)[![Total Downloads](https://camo.githubusercontent.com/b7807705454f0666830f42e212a4d609342b95437176b72d4cda2699564a3594/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d63656e7472696675676f2f646f776e6c6f616473)](https://packagist.org/packages/rasuvaeff/yii3-centrifugo)[![Build](https://github.com/rasuvaeff/yii3-centrifugo/actions/workflows/build.yml/badge.svg)](https://github.com/rasuvaeff/yii3-centrifugo/actions/workflows/build.yml)[![Static analysis](https://github.com/rasuvaeff/yii3-centrifugo/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/rasuvaeff/yii3-centrifugo/actions/workflows/static-analysis.yml)[![Psalm Level](https://camo.githubusercontent.com/11df3e084225958342e48391e4d4a7b9991faf4f175410e96a69708112266405/68747470733a2f2f73686570686572642e6465762f6769746875622f7261737576616566662f796969332d63656e7472696675676f2f6c6576656c2e737667)](https://shepherd.dev/github/rasuvaeff/yii3-centrifugo)[![License](https://camo.githubusercontent.com/553ce11667f5d4194cb74536b0390df11a8e785b3f88f85a804437ca1173d5ed/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d63656e7472696675676f2f6c6963656e7365)](https://packagist.org/packages/rasuvaeff/yii3-centrifugo)

Centrifugo v6 integration for Yii3: full HTTP server API client, JWT connection/subscription token issuers, and PSR-15 proxy event handlers (connect, subscribe, publish, refresh, sub\_refresh, rpc).

> Using an AI coding assistant? [llms.txt](llms.txt) has a compact API reference you can paste into context.

Requirements
------------

[](#requirements)

- PHP 8.3–8.5
- Centrifugo v6
- A PSR-18 HTTP client (e.g. `guzzlehttp/guzzle`, `symfony/http-client`)
- A PSR-17 factory (e.g. `nyholm/psr7`, `guzzlehttp/psr7`)

Installation
------------

[](#installation)

```
composer require rasuvaeff/yii3-centrifugo
```

Then configure in `config/params.php`:

```
'centrifugo' => [
    'api_url'            => 'http://localhost:8000',
    'api_key'            => 'your-api-key',
    'token_hmac_secret'  => 'your-hmac-secret-at-least-32-chars',
    'token_ttl'          => 3600,
],
```

Usage
-----

[](#usage)

### Server API Client

[](#server-api-client)

`CentrifugoClient` provides all Centrifugo v6 OSS HTTP API methods. It requires a PSR-18 client and PSR-17 factories to be bound in the DI container.

```
use Rasuvaeff\Yii3Centrifugo\CentrifugoClient;
use Rasuvaeff\Yii3Centrifugo\BatchCommand;

$client = $container->get(CentrifugoClient::class);

// Publish to a channel
$client->publish(channel: 'news', data: ['title' => 'Breaking news']);

// Broadcast to multiple channels
$client->broadcast(channels: ['news', 'alerts'], data: ['ping' => 1]);

// Manage subscriptions
$client->subscribe(user: '42', channel: 'private#42');
$client->unsubscribe(user: '42', channel: 'private#42');

// Disconnect a user
$client->disconnect(user: '42');

// Presence
$presence = $client->presence(channel: 'news');
$stats = $client->presenceStats(channel: 'news');

// History
$history = $client->history(channel: 'news', limit: 50);
$client->historyRemove(channel: 'news');

// Cluster info
$channels = $client->channels(pattern: 'news*');
$info = $client->info();

// Batch (multiple commands in one HTTP request)
$client->batch(
    new BatchCommand(method: 'publish', params: ['channel' => 'a', 'data' => []]),
    new BatchCommand(method: 'publish', params: ['channel' => 'b', 'data' => []]),
);
```

MethodDescription`publish(channel, data)`Publish to one channel`broadcast(channels, data)`Publish to many channels`subscribe(user, channel)`Subscribe user server-side`unsubscribe(user, channel)`Unsubscribe user server-side`disconnect(user, client?, whitelist?)`Disconnect user`refresh(user, client?, expireAt?)`Refresh connection`presence(channel)`Detailed presence info`presenceStats(channel)`Aggregated presence counts`history(channel, limit?, reverse?, since?)`Channel message history`historyRemove(channel)`Clear channel history`channels(pattern?)`List active channels`info()`Cluster node info`batch(BatchCommand ...)`Multiple commands in one request### JWT Token Issuance

[](#jwt-token-issuance)

```
use Rasuvaeff\Yii3Centrifugo\Token\ConnectionTokenIssuer;
use Rasuvaeff\Yii3Centrifugo\Token\SubscriptionTokenIssuer;

// Connection token (sent to client on login)
$issuer = $container->get(ConnectionTokenIssuer::class);
$jwt = $issuer->issue(
    userId: '42',
    ttl: 3600,
    channels: ['news'],       // optional auto-subscribe
    info: ['name' => 'Alice'], // optional user info
);

// Subscription token (sent when client requests private channel access)
$subIssuer = $container->get(SubscriptionTokenIssuer::class);
$jwt = $subIssuer->issue(
    userId: '42',
    channel: 'private#42',
    ttl: 3600,
    info: ['role' => 'admin'],
);
```

### Proxy Events

[](#proxy-events)

Centrifugo can proxy connection lifecycle events to your backend over HTTP. Configure endpoints in `centrifugo.json`:

```
{
    "proxy": {
        "connect": {"endpoint": "http://app/centrifugo/connect", "timeout": "3s"},
        "subscribe": {"endpoint": "http://app/centrifugo/subscribe", "timeout": "3s"}
    }
}
```

Register routes in your Yii3 app:

```
use Rasuvaeff\Yii3Centrifugo\Proxy\Action\ConnectAction;
use Rasuvaeff\Yii3Centrifugo\Proxy\Action\SubscribeAction;

Route::post('/centrifugo/connect', ConnectAction::class),
Route::post('/centrifugo/subscribe', SubscribeAction::class),
```

Implement the handler interface in your application:

```
use Rasuvaeff\Yii3Centrifugo\Proxy\Handler\ConnectProxyHandler;
use Rasuvaeff\Yii3Centrifugo\Proxy\Request\ConnectRequest;
use Rasuvaeff\Yii3Centrifugo\Proxy\Response\ProxyDisconnect;
use Rasuvaeff\Yii3Centrifugo\Proxy\Response\ProxyError;
use Rasuvaeff\Yii3Centrifugo\Proxy\Response\ProxyResult;

final readonly class AppConnectHandler implements ConnectProxyHandler
{
    public function __construct(private AuthService $auth) {}

    #[\Override]
    public function handle(ConnectRequest $request): ProxyResult|ProxyError|ProxyDisconnect
    {
        $userId = $this->auth->getUserFromRequest($request);

        if ($userId === null) {
            return new ProxyDisconnect(code: 4001, reason: 'unauthorized');
        }

        return new ProxyResult(data: ['user' => $userId]);
    }
}
```

Bind your handler in the DI container:

```
// config/common/di/centrifugo.php
use Rasuvaeff\Yii3Centrifugo\Proxy\Handler\ConnectProxyHandler;

return [
    ConnectProxyHandler::class => AppConnectHandler::class,
];
```

#### Available proxy handlers

[](#available-proxy-handlers)

Handler interfaceAction classCentrifugo event`ConnectProxyHandler``ConnectAction`Client connects`RefreshProxyHandler``RefreshAction`Connection refresh`SubscribeProxyHandler``SubscribeAction`Client subscribes to channel`PublishProxyHandler``PublishAction`Client publishes to channel`SubRefreshProxyHandler``SubRefreshAction`Subscription refresh`RpcProxyHandler``RpcAction`Client RPC call#### Proxy response types

[](#proxy-response-types)

TypeJSON envelopeCode range`ProxyResult(array $data)``{"result": {...}}`—`ProxyError(int $code, string $message)``{"error": {"code": N, "message": "..."}}`400–1999`ProxyDisconnect(int $code, string $reason)``{"disconnect": {"code": N, "reason": "..."}}`4000–4999Security
--------

[](#security)

- Proxy endpoints must be reachable only from the Centrifugo server (network ACL or shared secret header via `proxy.http_headers` config).
- HMAC secret and API key are injected from params/env, never hard-coded.
- `CentrifugoApiException` is thrown on Centrifugo API errors (non-zero `error` in response).
- `ProxyError` and `ProxyDisconnect` validate code ranges in constructors — invalid codes throw `InvalidArgumentException`.

Examples
--------

[](#examples)

See [`examples/`](examples/) for runnable scripts.

Development
-----------

[](#development)

```
make install
make build
make cs-fix
make psalm
make test
```

No PHP or Composer on the host — all commands run inside `composer:2` Docker container.

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

websocketrealtimeyii3centrifugo

###  Code Quality

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-centrifugo/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-centrifugo/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-centrifugo)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6513.9M11](/packages/aporat-store-receipt-validator)

PHPackages © 2026

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