pavelmgn/laravel-centrifugo
Composer 安装命令:
composer require pavelmgn/laravel-centrifugo
包简介
Centrifugo broadcaster for laravel
关键字:
README 文档
README
Documentation EN | RU
Laravel + Centrifugo
Centrifugo broadcast driver for Laravel 9 - 12
Introduction
Centrifugo broadcaster for Laravel is based on:
Features
- Compatibility with the latest version of Centrifugo v6.2.3 🚀
- Wrapper for Centrifugo HTTP API 🔌
- JWT token authentication (HMAC algorithm) for anonymous, authorized users, and private channels 🗝️
Requirements
- PHP 8.0 - 8.4
- Laravel 9 - 12
- Guzzlehttp/Guzzle 6 - 7
- Centrifugo Server v6 or newer (see here)
Installation
For Laravel 9-10:
composer require denis660/laravel-centrifugo
For Laravel 11-12, there are specific instructions below.
Select the version you need
| Version | PHP | Laravel | Centrifugo | Notes |
|---|---|---|---|---|
5.* |
>= 8.0 |
9 - 12 |
5-6 |
Current version |
3.0.* |
>= 7.4 |
8.75.* - 10 |
4-5 |
Previous version |
By default, broadcasting is disabled in new Laravel 11 applications. You can enable broadcasting using the install Artisan command:
php artisan install:broadcasting
If asked whether to install Reverb, answer “no.”
Then, install the package for working with Centrifugo via composer by running the following command:
composer require denis660/laravel-centrifugo
Configuration
Run the centrifuge:install command, which will publish the configuration file and generate the necessary environment variables in your .env file with default values.
php artisan centrifuge:install
Credentials
To establish a connection with Centrifugo, you need to provide credentials from your Centrifugo server's config.json file. Laravel will generate example keys that you should replace with your actual server credentials. You can specify these credentials with the following environment variables:
Required parameters:
CENTRIFUGO_TOKEN_HMAC_SECRET_KEY=token_hmac_secret_key-from-centrifugo-config
CENTRIFUGO_API_KEY=api_key-from-centrifugo-config
Optional parameters, modify if needed:
CENTRIFUGO_URL=http://localhost:8000
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=false
Make sure to check the BROADCAST_DRIVER parameter in the .env file:
BROADCAST_DRIVER=centrifugo
Client SDKs
For working with clients, see the Client SDK API
Here is a list of SDKs supported by Centrifugal Labs:
- JavaScript — for browser, NodeJS, and React Native
- Golang — for Go language
- Dart — for Dart and Flutter (mobile and web applications)
- Swift — for native iOS development
- Java — for native Android and general Java development
- Python — real-time SDK for Python on top of asyncio
Basic Usage
Set up your Centrifugo server as detailed in the official documentation For sending events, refer to the official Laravel documentation
Here is a simple example of client usage:
<?php declare(strict_types = 1); namespace App\Http\Controllers; use denis660\Centrifugo\Centrifugo; use Illuminate\Support\Facades\Auth; class ExampleController { public function example(Centrifugo $centrifugo) { // Send a message to the news channel $centrifugo->publish('news', ['message' => 'Hello world']); // Generate a connection token $token = $centrifugo->generateConnectionToken((string)Auth::id(), 0, [ 'name' => Auth::user()->name, ]); // Generate a token for a private channel connection $apiSign = $centrifugo->generatePrivateChannelToken((string)Auth::id(), 'channel', time() + 5 * 60, [ 'name' => Auth::user()->name, ]); // Get a list of active channels $centrifugo->channels(); // Get information about the news channel and its active clients $centrifugo->presence('news'); } }
Methods for generating client tokens
| Method | Description |
|---|---|
generateConnectionToken |
Generate a token for connection |
generatePrivateChannelToken |
Generate a private token for a private channel |
API Methods
| Method | Description |
|---|---|
publish |
Send a message to a channel |
broadcast |
Send a message to multiple channels. |
presence |
Get presence information for a channel (all clients currently subscribed to this channel). |
presenceStats |
Get summary information for a channel (number of clients). |
history |
Get channel history (list of recent messages sent to the channel). |
historyRemove |
Remove channel history. |
subscribe |
Subscribe a user to a channel |
unsubscribe |
Unsubscribe a user from a channel. |
disconnect |
Disconnect a user by their ID. |
channels |
List current active channels. |
info |
Statistical information about running server nodes. |
License
MIT License. Please read the License File for more information.
Support the Project
USDT wallet: TUYJrA9VRtXhDFooESHyT8dQSyg5zmtUg7
Network: TRC20
Contributing 🤝
pavelmgn/laravel-centrifugo 适用场景与选型建议
pavelmgn/laravel-centrifugo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「websocket」 「Socket」 「laravel」 「real time」 「web socket」 「centrifugo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pavelmgn/laravel-centrifugo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pavelmgn/laravel-centrifugo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pavelmgn/laravel-centrifugo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
NO LIBRARIES socket per page bridge for your Laravel application.
WebSocket view engine
Free PHP WebSocket
A light weight PHP http client implements PSR7, use socket/curl for sending requests.
Alfabank REST API integration
This is a PHP Framework base on Swoole
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-20