【问题标题】:How to run ratchet websocket server in parallel with apache server如何与 apache 服务器并行运行棘轮 websocket 服务器
【发布时间】:2019-12-29 23:18:01
【问题描述】:

我正在尝试使用棘轮和 php 创建一个聊天应用程序。我创建了 websocket 服务器来监听 server.php 文件中的 8080 端口,但在托管后我找不到如何将它与 apache 服务器并行运行。

server.php

<?php

require 'vendor/autoload.php';

use Ratchet\Server\IoServer;

use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Core\Socket\Chat;
use Core\Router;
use Core\Request;

$server = IoServer::factory(
  new HttpServer(
    new WsServer(
      new Chat()
    )
  ),
  8080
);

$server->run();

index.php

<!DOCTYPE html>
<html>
  <head>
    <title>A Chat App</title>
  </head>
  <body>
    <h1>Chat App</h1>
  </body>
  <script>
    const socket = new WebSocket('ws://localhost:8080');

    socket.addEventListener('open', event => {
      console.log('Connection established');
      socket.send('Hey There Everyone');
    });

    socket.addEventListener('message', message => {
      console.log(message);
    });
  </script>
</html>

当我在 localhost 上使用 cmd 和 index.php 运行 server.php 时,这可以正常工作。但是在托管在网络托管服务上之后如何并行运行这些文件。

【问题讨论】:

    标签: php websocket routing chat ratchet


    【解决方案1】:

    您正在运行两个想要使用相同端口的不同进程。所以这个设置是不可能的。但是您可以让 apache 为您的 websocket 脚本提供服务,而不是使用命令行。

    查看帖子的链接,其中包含您可以采取的方法的详细信息: Setting up a websocket on Apache?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2021-01-30
      • 1970-01-01
      • 2011-05-06
      • 2011-05-20
      相关资源
      最近更新 更多