PHPackages                             roadrunner-php/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. roadrunner-php/centrifugo

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

roadrunner-php/centrifugo
=========================

RoadRunner: Centrifugo bridge

2.2.1(11mo ago)141.9M↓56%25MITPHPPHP &gt;=8.1CI failing

Since Nov 11Pushed 11mo ago4 watchersCompare

[ Source](https://github.com/roadrunner-php/centrifugo)[ Packagist](https://packagist.org/packages/roadrunner-php/centrifugo)[ Docs](https://roadrunner.dev/)[ GitHub Sponsors](https://github.com/sponsors/roadrunner-server)[ RSS](/packages/roadrunner-php-centrifugo/feed)WikiDiscussions 2.x Synced 1w ago

READMEChangelog (6)Dependencies (8)Versions (8)Used By (5)

[   ![](https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8) ](https://roadrunner.dev)RoadRunner Centrifugo Bridge
============================

[](#roadrunner-centrifugo-bridge)

[![PHP Version Require](https://camo.githubusercontent.com/06b74e1a96bd20a74ec7179dfd16a7d11791d410d38a567293c8a1a545ae6b2c/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f63656e7472696675676f2f726571756972652f706870)](https://packagist.org/packages/roadrunner-php/centrifugo)[![Latest Stable Version](https://camo.githubusercontent.com/eb2850f46eeb7822b8f25d519fc52d75ab90d592f448b94a8e0b5887e3bb1e44/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f63656e7472696675676f2f762f737461626c65)](https://packagist.org/packages/roadrunner-php/centrifugo)[![phpunit](https://github.com/roadrunner-php/centrifugo/actions/workflows/phpunit.yml/badge.svg)](https://github.com/roadrunner-php/centrifugo/actions)[![psalm](https://github.com/roadrunner-php/centrifugo/actions/workflows/psalm.yml/badge.svg)](https://github.com/roadrunner-php/centrifugo/actions)[![Codecov](https://camo.githubusercontent.com/82ef5f85d59296ff5e850db2a840fab81b7dcf1902bf3ae37addeb0bc8294981/68747470733a2f2f636f6465636f762e696f2f67682f726f616472756e6e65722d7068702f63656e7472696675676f2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/roadrunner-php/centrifugo/)[![Total Downloads](https://camo.githubusercontent.com/5ca6312f767268a9d446fb4e91db724f0550d9381a33c84bb19b7e81295cd138/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f63656e7472696675676f2f646f776e6c6f616473)](https://packagist.org/packages/roadrunner-php/centrifugo)

This repository contains the codebase PHP bridge using RoadRunner centrifuge plugin.

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

[](#installation)

To install application server and Jobs codebase

```
composer require roadrunner-php/centrifugo
```

You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:

```
composer require spiral/roadrunner-cli --dev
vendor/bin/rr get
```

Proxy Centrifugo requests to a PHP application
----------------------------------------------

[](#proxy-centrifugo-requests-to-a-php-application)

It's possible to proxy some client connection events from Centrifugo to the RoadRunner application server and react to them in a custom way. For example, it's possible to authenticate connection via request from Centrifugo to application backend, refresh client sessions and answer to RPC calls sent by a client over bidirectional connection.

The list of events that can be proxied:

- `connect` – called when a client connects to Centrifugo, so it's possible to authenticate user, return custom data to a client, subscribe connection to several channels, attach meta information to the connection, and so on. Works for bidirectional and unidirectional transports.
- `refresh` - called when a client session is going to expire, so it's possible to prolong it or just let it expire. Can also be used just as a periodical connection liveness callback from Centrifugo to app backend. Works for bidirectional and unidirectional transports.
- `sub_refresh` - called when it's time to refresh the subscription. Centrifugo itself will ask your backend about subscription validity instead of subscription refresh workflow on the client-side.
- `subscribe` - called when clients try to subscribe on a channel, so it's possible to check permissions and return custom initial subscription data. Works for bidirectional transports only.
- `publish` - called when a client tries to publish into a channel, so it's possible to check permissions and optionally modify publication data. Works for bidirectional transports only.
- `rpc` - called when a client sends RPC, you can do whatever logic you need based on a client-provided RPC method and params. Works for bidirectional transports only.

First you need to add `centrifuge` section to your RoadRunner configuration. For example, such a configuration would be quite feasible to run:

```
rpc:
  listen: tcp://127.0.0.1:6001

server:
  command: "php app.php"
  relay: pipes

centrifuge:
  proxy_address: "tcp://0.0.0.0:10001" # Centrifugo address
```

and centrifugo config:

```
{
  "admin": true,
  "api_key": "secret",
  "admin_password": "password",
  "admin_secret": "admin_secret",
  "allowed_origins": [
    "*"
  ],
  "token_hmac_secret_key": "test",
  "publish": true,
  "proxy_publish": true,
  "proxy_subscribe": true,
  "proxy_connect": true,
  "allow_subscribe_for_client": true,
  "proxy_connect_endpoint": "grpc://127.0.0.1:10001",
  "proxy_connect_timeout": "10s",
  "proxy_publish_endpoint": "grpc://127.0.0.1:10001",
  "proxy_publish_timeout": "10s",
  "proxy_subscribe_endpoint": "grpc://127.0.0.1:10001",
  "proxy_subscribe_timeout": "10s",
  "proxy_refresh_endpoint": "grpc://127.0.0.1:10001",
  "proxy_refresh_timeout": "10s",
  "proxy_sub_refresh_endpoint": "grpc://127.0.0.1:10001",
  "proxy_sub_refresh_timeout": "1s",
  "proxy_rpc_endpoint": "grpc://127.0.0.1:10001",
  "proxy_rpc_timeout": "10s"
}
```

> **Note**`proxy_connect_endpoint`, `proxy_publish_endpoint`, `proxy_subscribe_endpoint`, `proxy_refresh_endpoint`, `proxy_sub_refresh_endpoint`, `proxy_rpc_endpoint` - endpoint address of roadrunner server with activated `centrifuge` plugin.

To init abstract RoadRunner worker:

```
