简体   繁体   English

Laravel 与 websockets 实时聊天

[英]Laravel real time chat with websockets

Hi I am tring to build a real time chat application with websockets but whenever I try to go visit http://127.0.0.1:8000/laravel-websockets I get error 404 not found.嗨,我正在尝试使用 websockets 构建一个实时聊天应用程序,但是每当我尝试访问http://127.0.0.1:8000/laravel-websockets 时,我都会收到错误 404 未找到。 I did all the steps like in the documentation so I don't understand what might be the issue: Followed all the steps here:我完成了文档中的所有步骤,所以我不明白可能是什么问题:按照此处的所有步骤操作:

https://beyondco.de/docs/laravel-websockets/basic-usage/starting

websockets config网络套接字配置

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'path' => env('PUSHER_APP_PATH'),
        'capacity' => null,
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
]

.env file .env 文件

PUSHER_APP_ID=anyID
PUSHER_APP_KEY=anyKey
PUSHER_APP_SECRET=anySecret
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

First of all, as the documentation refers there is no line capacity second thing please make sure that you have followed the steps correctly, and make sure you set your APP_URL in the .env file properly.首先,如文档是指没有线的产能第二件事情,请确保您已正确执行的步骤,并确保您在.ENV文件中设置你的APP_URL正常。 Try using Homestead or Valet as sometimes setting the URL to localhost or 127.0.0.1:8000 doesn't seem to work properly.尝试使用HomesteadValet,因为有时将 URL 设置为 localhost 或 127.0.0.1:8000 似乎无法正常工作。

I have just did a quick test to check if something might go wrong but all seems to be working just as expected.我刚刚做了一个快速测试来检查是否有问题,但一切似乎都按预期工作。

在此处输入图片说明

.env file: .env 文件:

APP_URL=http://homestead.laravel_websocket
...
PUSHER_APP_ID=moayadapp
PUSHER_APP_KEY=moayadkey
PUSHER_APP_SECRET=moayadsecret
PUSHER_APP_CLUSTER=mt1

websockets.php websockets.php

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'path' => env('PUSHER_APP_PATH'),
//        'capacity' => null,
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
],

I fixed this problem by running this command我通过运行这个命令解决了这个问题

php artisan config:clear php工匠配置:清除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM