作者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/m.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