slivka-b/laravel-centrifugo
Composer 安装命令:
composer require slivka-b/laravel-centrifugo
包简介
Centrifugo broadcaster for laravel 6.20.26-8 and Centrifugo >= 2.8.1
关键字:
README 文档
README
Documentation EN | RU
Laravel + Centrifugo
Centrifugo broadcast driver for Laravel 8.75.0 - 9
Introduction
Centrifugo broadcaster for laravel , based on:
Features
- Compatible with latest Centrifugo 3.2.0 🚀
- Wrapper over Centrifugo HTTP API 🔌
- Authentication with JWT token (HMAC algorithm) for anonymous, authenticated user and private channel 🗝️
Requirements
- PHP >= 7.4 , 8.0, 8.1
- Laravel 8.75.0 - 9.0
- guzzlehttp/guzzle 6 - 7
- Centrifugo Server 3.2.0 or newer (see here)
Installation
Require this package with composer:
composer req denis660/laravel-centrifugo
Open your config/app.php and add the following to the providers array:
'providers' => [ // And uncomment BroadcastServiceProvider App\Providers\BroadcastServiceProvider::class, ],
Open your config/broadcasting.php and add new connection like this:
'centrifugo' => [ 'driver' => 'centrifugo', 'token_hmac_secret_key' => env('CENTRIFUGO_TOKEN_HMAC_SECRET_KEY',''), 'api_key' => env('CENTRIFUGO_API_KEY',''), 'url' => env('CENTRIFUGO_URL', 'http://localhost:8000'), // centrifugo api url 'verify' => env('CENTRIFUGO_VERIFY', false), // Verify host ssl if centrifugo uses this 'ssl_key' => env('CENTRIFUGO_SSL_KEY', null), // Self-Signed SSl Key for Host (require verify=true) ],
Also you should add these two lines to your .env file:
CENTRIFUGO_TOKEN_HMAC_SECRET_KEY=token_hmac_secret_key-from-centrifugo-config
CENTRIFUGO_API_KEY=api_key-from-centrifugo-config
CENTRIFUGO_URL=http://localhost:8000
These lines are optional:
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=false
Don't forget to change BROADCAST_DRIVER setting in .env file!
BROADCAST_DRIVER=centrifugo
Basic Usage
To configure Centrifugo server, read official documentation
For broadcasting events, see official documentation of laravel
A simple client usage example:
<?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 message into channel $centrifugo->publish('news', ['message' => 'Hello world']); // Generate connection token $token = $centrifugo->generateConnectionToken((string)Auth::id(), 0, [ 'name' => Auth::user()->name, ]); // Generate private channel token $apiSign = $centrifugo->generatePrivateChannelToken((string)Auth::id(), 'channel', time() + 5 * 60, [ 'name' => Auth::user()->name, ]); //Get a list of currently active channels. $centrifugo->channels(); //Get channel presence information (all clients currently subscribed on this channel). $centrifugo->presence('news'); } }
Available methods
| Name | Description |
|---|---|
| publish(string $channel, array $data, $skipHistory = false) | Send message into channel. |
| broadcast(array $channels, array $data, $skipHistory = false) | Send message into multiple channel. |
| presence(string $channel) | Get channel presence information (all clients currently subscribed on this channel). |
| presenceStats(string $channel) | Get channel presence information in short form (number of clients). |
| history(string $channel, $limit = 0, $since = [], $reverse = false) | Get channel history information (list of last messages sent into channel). |
| historyRemove(string $channel) | Remove channel history information. |
| subscribe(string $channel, string $user, $client = '') | subscribe user from channel. |
| unsubscribe(string $channel, string $user, string $client = '') | Unsubscribe user from channel. |
| disconnect(string $user_id) | Disconnect user by it's ID. |
| channels(string $pattern = '') | Get channels information (list of currently active channels). |
| info() | Get stats information about running server nodes. |
| generateConnectionToken(string $userId = '', int $exp = 0, array $info = [], array $channels = []) | Generate connection token. |
| generatePrivateChannelToken(string $client, string $channel, int $exp = 0, array $info = []) | Generate private channel token. |
License
The MIT License (MIT). Please see [License File](https://github.com/denis660/laravel-centrifugo/blob/master/LICENSE for more information.
slivka-b/laravel-centrifugo 适用场景与选型建议
slivka-b/laravel-centrifugo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Socket」 「laravel」 「real time」 「web socket」 「centrifugo」 「broadcaster」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 slivka-b/laravel-centrifugo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slivka-b/laravel-centrifugo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 slivka-b/laravel-centrifugo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Get the real ip for laravel applications behind cloudflare's reverse proxy
Send events to a websocket real time engine though PHP
PHP library for Broadcastt HTTP API
Zend Framework 2 module for interacting with the Pusher REST API, built on top of ZfrPusher
Send events to a websocket real time engine though PHP
NO LIBRARIES socket per page bridge for your Laravel application.
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-21