gpt4 book ai didi

websocket - Ratchet PHP Websocket 持久化 Ubuntu 16.04

转载 作者:行者123 更新时间:2023-12-04 16:14:23 32 4
gpt4 key购买 nike

我的 websocket 文件:

<?php
require __DIR__ . '/../../../vendor/autoload.php';

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

require 'chat.php';

// Run the server application through the WebSocket protocol on port 8080
$app = new Ratchet\App("localhost", 8080, '0.0.0.0', $loop);
$app->route('/chat', new Chat, array('*'));

$app->run();

我按照本指南设置了我的 websocket:
https://blog.samuel.ninja/the-tutorial-for-php-websockets-that-i-wish-had-existed/

它在本地使用 php socket.php 工作(在 Windows 10 上用 xampp 测试)。
当我尝试在我的虚拟机 (ubuntu 16.04) 上部署时,出现以下错误:
WebSocket connection to 'ws://localhost:8080/chat?id=NDY=&group=43,60' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

PS:我尝试使用 php /var/www/path-to-websocket/socket.php 启动 websocket

我还需要使用服务而不是命令行来启动它,但是所描述的方法不起作用

最佳答案

尝试使用 SERVERNAME而是本地主机。

来自 PHP Ratchet :

Run your website and WebSocket server on the same machine using port 8080 for WebSockets and take the chance client proxies won't block traffic
Run your WebSocket server on its own server on port 80 under a subdomain (sock.example.com)
Put a reverse proxy (HAProxy or Varnish) in front of your webserver and WebSocket server

来源: http://socketo.me/docs/deploy

关于websocket - Ratchet PHP Websocket 持久化 Ubuntu 16.04,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43613172/

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