Laravel Socket.io已连接但未接收数据 [英] Laravel Socket.io Connected but not receiving data

查看:179
本文介绍了Laravel Socket.io已连接但未接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地环境中设置了一个工作节点服务器和Redis服务器,并能够在Laravel中成功使用socket.io.但是,当我尝试将更改推送到生产服务器时,我意识到socket.io无法正常工作.

I set up a working node server and Redis server on my local environment and was able to successfully use socket.io with Laravel. But when I tried to push my changes to the production server I realized that socket.io was not working properly.

当我在Google Chrome控制台中键入以下命令来调试socket.io时,它说它已经建立了连接,但它从未接收到数据.

When I typed in the following command in the Google Chrome console to debug socket.io it said that it had established a connection, but it could never received data.

localStorage.debug = "socket.io-client:socket"

我知道redis服务器有问题,因为其中一个表示它已连接到套接字.还有两个,如果我在事件类中写了die and dump,它就成功地死了.

I knew it was a problem with the redis server because one, it said it was connected to the socket. And two, if I wrote die and dump in the event class, it successfully died.

namespace App\Events;

class MyEvent implements ShouldBroadcast{
  public function broadcastOn(){
        dd("Successfully reached event");
        return new Channel($this->channel.'-channel');}}

最后,我知道它不可能是我的任何一个服务器,因为我能够从本地和远程主机卷曲redis服务器和节点服务器的两个端口.

Finally, I knew it couldn't be either of my servers, because I was able to curl both of the ports for the redis server and the node server from local and remote hosts.

这是一篇编辑过的帖子,显示了我的调试过程.我的原始帖子太含糊,因为我不知道如何调试此问题,但是如果您希望看到它,请查看编辑.

推荐答案

令人尴尬的是,我找到了解决方案.它检测到套接字但未通过的原因是因为我忘记了重置环境变量.因此,这一次我一直将其作为环境变量运行.

As embarrassing as this is, I found the solution. The reason it was detecting the socket, but not going through was because I forgot that environment variables got reset. So this whole time I was running this as my environment variables.

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

当我应该一直使用它的时候.

when I should have been using this.

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
SESSION_DRIVER=file
QUEUE_DRIVER=sync

这篇关于Laravel Socket.io已连接但未接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆