我正在尝试在Laravel中使用包创建一个RPC WebSocket。
当我点击连接按钮时,我能够在
我正在使用Ubuntu服务器,并定义了用于WebSocket命令的Supervisor。
当我点击连接按钮时,我能够在
laravel-websockets
端点看到仪表板,但它一直在控制台显示警告。WebSocket connection to '<URL>' failed: WebSocket is closed before the connection is established.
TestSockerHandler.php
:
<?php
namespace App\Websocket\SocketHandler;
use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use Ratchet\WebSocket\MessageComponentInterface;
class TestSocketHandler implements MessageComponentInterface
{
function onOpen(ConnectionInterface $conn)
{
// TODO: Implement onOpen() method.
dd($conn->httpRequest);
}
function onClose(ConnectionInterface $conn)
{
// TODO: Implement onClose() method.
}
function onError(ConnectionInterface $conn, \Exception $e)
{
// TODO: Implement onError() method.
}
public function onMessage(ConnectionInterface $conn, MessageInterface $msg)
{
// TODO: Implement onMessage() method.
}
}
web.php
:
\BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter::webSocket('/socket/test', \App\Websocket\SocketHandler\TestSocketHandler::class);
.env
:
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
PUSHER_APP_ID=livepost
PUSHER_APP_KEY=livepost_key
PUSHER_APP_SECRET=livepost_secret
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/mydomain.com/fullchain.pem"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/mydomain.com/privkey.pem"
LARAVEL_WEBSOCKETS_SSL_PASSPHRASE=""
LARAVEL_WEBSOCKETS_PORT=6001
composer.json
:
"pusher/pusher-php-server": "7.0.2"
"beyondcode/laravel-websockets": "^1.14"
我正在使用Ubuntu服务器,并定义了用于WebSocket命令的Supervisor。
/etc/supervisor/conf.d/websockets.conf
:
[program:websockets]
process_name=%(program_name)s
command=sudo php artisan websockets:serve --port=8443
directory=/home/my-app/www
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/home/my-app/www/storage/logs/websockets.log
supervisor
状态:
root@my-app:/etc/supervisor/conf.d# supervisorctl status
websockets RUNNING pid 872475, uptime 1:41:26
我已经浪费了两天时间但是没找到原因。只是因为没有任何错误,我不知道检查或搜索什么。有没有任何保存错误日志之类的东西?我一直在持续检查 laravel.log
和 nginx 的 error.log
,但是关于 WebSocket 没有任何记录。
/etc/supervisor/conf.d/websockets.conf
中定义了command=sudo php artisan websockets:serve --port=8443
。 - Vüsal Hüseynli/etc/supervisor/conf.d/websockets.conf
中定义了command=sudo php artisan websockets:serve --port=8443
。 - Vüsal Hüseynlisudo
权限,但是websocket仍然无法工作。 - Macdonald