skoniks / php_cent
Centrifugo (Centrifuge) [1.0+] PHP 服务器 REDIS 与 HTTP API 实现适用于 Laravel 5+
v2.8
2018-11-02 16:15 UTC
Requires
README
Centrifugo (Centrifuge) [1.0+] PHP 服务器 REDIS 与 HTTP API 实现适用于 Laravel 5+ 不兼容 Centrifugo [2.0+],将稍后更新!
基本安装
- 运行
composer require skoniks/php_cent
与composer update
- 创建如下所示的
config/centrifugo.php
- 在
config/app.php
中添加如下所示的别名
对于 Laravel 5.5+ 使用版本 >= "2.5"
配置示例 config/centrifugo.php
别名添加 config/app.php
'aliases' => [ ... 'Centrifugo'=> SKONIKS\Centrifugo\Centrifugo::class, ]
设置 Redis 作为传输
- 将您的 Redis 连接添加到
config/database.php
- 将
config/centrifugo.php
更改为 Redis 设置
添加 Redis 连接 config/database.php
... 'redis' => [ ... 'centrifugo' => [ 'host' => '127.0.0.1', 'password' => '', 'port' => 6379, 'database' => 1, ], ], ...
Redis 支持的传输
请确保 HTTP 连接必须独立于 Redis 连接工作。这是因为 Redis 传输只提供以下方法
- 'publish'
- 'broadcast'
- 'unsubscribe'
- 'disconnect'
Redis 不提供这些方法
- presence
- history
- channels
- stats
- node
模块使用示例 [发送您的请求]
<?php use Centrifugo; class Controller { public function _function(){ // declare Centrifugo $centrifugo = new Centrifugo(); // generating token example $current_time = time(); $user_id = '1234567890'; $token = Centrifugo::token($user_id, $current_time, 'custom info'); // publishing example $centrifugo->publish("channel" , ["custom data"]); // list of awailible methods: $response = $centrifugo->publish($channel, $data); $response = $centrifugo->unsubscribe($channel, $user_id); $response = $centrifugo->disconnect($user_id); $response = $centrifugo->presence($channel); $response = $centrifugo->history($channel); $response = $centrifugo->channels(); $response = $centrifugo->stats(); $response = $centrifugo->node(); $token = Centrifugo::token($user_id, $timestamp, $info); // $response == false | when error }