php - 请确保在 .larave 7 中安装并启用了 PHP Redis 扩展?
问题描述
我正在尝试为聊天组创建状态通道,我设置了redis并且每件事都是必需的,但是这个错误出现了但是我运行
作曲家需要 predis/predis
并使用 * laravel echo server* 。我创建事件来收听聊天应用程序和此代码消息事件:
class Message implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct( \App\Message $message)
{
$this->message=$message;
//dd();
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('chat-group');
}
}
消息控制器:
public function store(Request $request){
$m=new Message();
$m->content=$request->message;
$m->user_id=Auth::id();
$m->save();
broadcast(new \App\Events\Message($m))->toOthers();
}
应用程序js:
window.Echo.channel('chat-group')
.listen('Message', (e) => {
console.log(e.message.content);
});
D:\work\chat>redis-cli ping PONG 结果:
{
"message": "Please make sure the PHP Redis extension is installed and enabled.",
"exception": "LogicException",
"file":
]
}
环境:
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_CLIENT=predis
REDIS_PASSWORD=null
REDIS_PORT=6379
laravel 回声服务器:
L A R A V E L E C H O S E R V E R
version 1.6.2
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
[1:04:07 PM] - Preparing authentication request to: http://localhost:8000
[1:04:07 PM] - Sending auth request to: http://localhost:8000/broadcasting/auth
[1:04:07 PM] - fZvJEifYevcj805nAAAA joined channel: chat-group
[1:04:07 PM] - fZvJEifYevcj805nAAAA authenticated for: presence-online
[1:04:07 PM] - fZvJEifYevcj805nAAAA joined channel: presence-online
[1:04:08 PM] - Preparing authentication request to: http://localhost:8000
[1:04:08 PM] - Sending auth request to: http://localhost:8000/broadcasting/auth
[1:04:08 PM] - kif6o7whupgU9GH2AAAB joined channel: chat-group
[1:04:08 PM] - kif6o7whupgU9GH2AAAB authenticated for: presence-online
[1:04:08 PM] - kif6o7whupgU9GH2AAAB joined channel: presence-online
解决方案
推荐阅读
- reactjs - Webpack 开发服务器 - 在多个端口上运行多个应用程序
- javascript - 为什么 setInterval 不等待指定时间?
- matlab - 使用 eig 的特征值
- ios - 找到链接到 stdc++ 的依赖项
- linux - Makefile:目标依赖 - 如何始终制作它?
- inheritance - (Kotlin)将参数从数据类构造函数传递给超级构造函数?
- php - 获取调用者函数参数
- android - 像 Instagram Stories 头像的 ImageView?
- sass - 下拉菜单不适用于带有 sass 的 bootstrap4
- python - 从LSTM,Keras中每个时期的最后一层获取输出