gpt4 book ai didi

php - Laravel 回显服务器无法在生产服务器中运行

转载 作者:IT王子 更新时间:2023-10-29 05:55:36 24 4
gpt4 key购买 nike

我在使用 socket.io 作为 laravel echo 的广播时遇到问题。

我尝试了什么:

php artisan cache:clear
php artisan config:clear

我可以在日志中看到用户连接:

0|Socket-Connection  | [11:17:00 AM] - ********** joined channel: test-channel
0|Socket-Connection | [11:17:01 AM] - ********** authenticated for: private-user.1
0|Socket-Connection | [11:17:01 AM] - ********** joined channel: private-user.1

我的队列正在运行并正确记录所有事件。

我可以在redis控制台完美的看到redis我的事件和数据库通知。

但是没有广播任何事件,我也没有在 laravel-echo-server 控制台中看到它们。一切都在我的本地主机上工作,但在生产中却没有,我失去了理智。

这是我的 laravel echo JS:

if (typeof io !== 'undefined') {
console.log(window.location.origin);
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.origin + ':6001',
auth: {
headers: {
Authorization: 'Bearer ' + bearerToken,
},
}
});
window.Echo.private('user.' + user_id).notification((notification) => {
console.log(notification);
});
}

在我的用户模型中,我定义了这个:

/**
* @return string
*/
public function receivesBroadcastNotificationsOn()
{
return 'user.' . $this->id;
}

在我的 channel 中我有这个:

Broadcast::channel('user.{id}', function ($user, $id) {
return (int)$user->id === (int)$id;
});

这是我的 echo 服务器配置,其中所有路径都是正确的。我在本地主机上测试了相同的文件,一切正常:

var echo = require('laravel-echo-server/dist');

echo.run({
"appKey": "myappkey",
"authHost": "https://url",
"authEndpoint": "/broadcasting/auth",
"database": "redis",
"clients": [
{
"appId": "myappid",
"key": "mykey"
}
],
"databaseConfig": {
"redis": {
"port": "6379",
"host": "myhost",
"password": "mysupersecretpassword"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "url",
"port": "6001",
"protocol": "https",
"referrers": [],
"sslCertPath": "/path/to/certificate.pem",
"sslKeyPath": "/path/to/key",
"verifyAuthPath": true,
"verifyAuthServer": false
});

我的 redis 日志在发布数据库通知时显示了这一点

1534840681.110359 [0 "IP ADDRESS HERE"] "PUBLISH" "private-user.2" "{\"event\":\"Illuminate\\\\Notifications\\\\Events\\\\BroadcastNotificationCreated\",\"data\":{\"title\":\"Ravim CONVULEX 50MG\\/ML  staatust muudeti\",\"notification_type\":\"element-soft-delete\",\"message\":\"Ravimi CONVULEX 50MG\\/ML  staatust muutis kasutaja Kalle \",\"url\":\"https:\\/\\/www.app.riskomed.com\\/admin\\/brands\\/all\",\"id\":\"30c37d0d-c39b-41bf-93fc-afa0c78ca9db\",\"type\":\"App\\\\Notifications\\\\API\\\\Management\\\\Medical\\\\Brands\\\\BrandSoftDeleteNotification\",\"socket\":null},\"socket\":null}"

编辑

这是我的通知

        /**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail', 'database', 'broadcast'];
}

最佳答案

我看到您在生产服务器中使用“https”协议(protocol),因此您需要定义“sslCertPath”和“sslKeyPath”:

来自文档

使用 SSL 运行

  • 您的客户端实现必须从以下位置访问 socket.io 客户端https。
  • 服务器配置必须设置要使用的服务器主机https。
  • 服务器配置应包括您的 ssl 证书和位于您服务器上的 key 的路径。

关于php - Laravel 回显服务器无法在生产服务器中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51944819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com