棘轮 PHP Websocket 持久 Ubuntu 16.04
Ratchet PHP Websocket persistent Ubuntu 16.04
我的 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
而不是 localhost。
来自 PHP 棘轮:
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
我的 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
我还需要用服务而不是命令行来启动它,但是描述的方法不起作用
尝试使用 SERVERNAME
而不是 localhost。
来自 PHP 棘轮:
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