首页 > 解决方案 > 请确保在 .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

标签: phplaravelredislaravel-echo

解决方案


推荐阅读