作者wuwt4y (Poky)
看板PHP
标题[请益] Laravel Broadcast + redis 问题
时间Tue Apr 10 11:56:52 2018
环境是 ubuntu apache2 php7.1 laravel5.6 redis-cli 3.0.6
我想以laravel redis 来实现websocket
以下是我的程式码
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ChatTest implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $username;
/**
* Create a new event instance.
*
* @param $username
*/
public function __construct($username)
{
$this->username = $username;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new Channel('aabaa');
}
}
--------------------------------------------------
routes/channels.php
Broadcast::channel('aabaa', true);
--------------------------------------------------
我直接bash
用redis-cli 监听 频道 aabaa
但是无论我怎麽触发事件
Route::get('/publish', function () {
event(new App\Events\ChatTest('ff'));
return 'event';
});
都没有收到任何消息
当然直接用redis-cli 推 会收到
不晓得是哪里出了问题?
还请各位高手指点迷津
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.34.127.221
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1523332614.A.0C8.html
1F:推 crossdunk: 你确定他有推进去REDIS里面吗 04/10 12:39
2F:→ wuwt4y: Redis::publish('aabaa', json_encode(['foo' => 'bar'])) 04/10 13:33
3F:→ wuwt4y: 这样也可以收到,所以我想是我的ChatTest events 出问题 04/10 13:33
4F:→ wuwt4y: .env BROADCAST_DRIVER=redis || QUEUE_DRIVER=redis 04/10 13:34
5F:→ wuwt4y: 不知道我的ChatTest 哪里出问题 04/10 13:34
6F:→ wuwt4y: 以解决,解决方法 使用redis monitor 监控redis 得知queue 04/11 10:01
7F:→ wuwt4y: 出问题,queue开启 即正常推送至client端 04/11 10:02