emprove/centrifuge-broadcaster
Composer 安装命令:
composer require emprove/centrifuge-broadcaster
包简介
Centrifuge broadcaster for laravel ^6
README 文档
README
Attention! Maybe some diff with IRL.
- This package forked from "LaraComponents" to fit new Centrifugo v2.
- Drop Redis support (v2 don't support it), see official migration guide.
- Update generateToken(user id, timestamp, info) method (v2 uses only jwt auth workflow).
Introduction
Centrifuge broadcaster for laravel ^6
Requirements
- PHP 7.2+
- Laravel 6+
- Centrifugo Server 2 or newer (see here)
Installation
Require this package with composer:
composer require emprove/centrifuge-broadcaster
Open your config/app.php and add the following to the providers array:
'providers' => [ // ... Emprove\Centrifugo\CentrifugoServiceProvider::class, // And uncomment BroadcastServiceProvider App\Providers\BroadcastServiceProvider::class, ],
Open your config/broadcasting.php and add the following to it:
'connections' => [ 'centrifuge' => [ 'driver' => 'centrifuge', 'url' => env('CENTRIFUGE_URL', 'http://127.0.0.1:8000'), 'token_ttl' => env('CENTRIFUGE_TOKEN_TTL', 3600), 'token_issuer' => env('APP_URL', 'default'), 'secret' => env('CENTRIFUGE_SECRET', null), 'api_key' => env('CENTRIFUGE_API_KEY', null), 'ssl_key' => env('CENTRIFUGE_SSL_KEY', null), 'verify' => env('CENTRIFUGE_VERIFY', false), ], // ... ],
You can also add a configuration to your .env file:
CENTRIFUGE_API_KEY=very-long-secret-api-key
CENTRIFUGE_SECRET=very-long-secret-key
CENTRIFUGE_URL=http://localhost:8000
CENTRIFUGE_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGE_TOKEN_TTL=3600 # seconds
CENTRIFUGE_VERIFY=false
Do not forget to install the broadcast driver
BROADCAST_DRIVER=centrifuge
Basic Usage
To configure the Centrifugo server, read the official documentation
For broadcasting events, see the official documentation of laravel
A simple example of using the client:
<?php namespace App\Http\Controllers; use Emprove\Centrifugo\Contracts\Centrifugo; class ExampleController extends Controller { public function home(Centrifugo $centrifuge) { // Send message into channel $centrifuge->publish('channel-name', [ 'key' => 'value' ]); // Generate api sign $apiSign = $centrifuge->generateApiSign('data'); // ... } }
Available methods
| Name | Description |
|---|---|
| publish(string $channel, array $data, string $client = null) | Send message into channel. |
| broadcast(array $channels, array $data, string $client = null) | Send message into multiple channel. |
| presence(string $channel) | Get channel presence information (all clients currently subscribed on this channel). |
| history(string $channel) | Get channel history information (list of last messages sent into channel). |
| unsubscribe(string $user_id, string $channel = null) | Unsubscribe user from channel. |
| disconnect(string $user_id) | Disconnect user by its ID. |
| channels() | Get channels information (list of currently active channels). |
| stats() | Get stats information about running server nodes. |
| generateToken(string $userId) | Generate JWT token for client. |
| generateApiSign(string $data) | Generate api sign. |
License
The MIT License (MIT). Please see License File for more information.
emprove/centrifuge-broadcaster 适用场景与选型建议
emprove/centrifuge-broadcaster 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.32k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「centrifuge」 「centrifugo」 「broadcaster」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emprove/centrifuge-broadcaster 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emprove/centrifuge-broadcaster 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emprove/centrifuge-broadcaster 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Centrifuge broadcaster for laravel >= 5.3
Centrifugo broadcaster for laravel 9 and Centrifugo 4
Centrifugo (Centrifuge) [1.0+] PHP Server REDIS & HTTP API implementation for Laravel 5+
Centrifuge broadcaster for laravel >= 5.3, support Centrifuge v2
PHP library to communicate with Centrifugo HTTP API
Centrifuge broadcaster for laravel >= 5.3, support Centrifuge v2
统计信息
- 总下载量: 19.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-05