websocket与活动服务器的持久连接


Persistent connection of websocket into live server

我用codeigniter实现了rachet websocket,它在localhost中工作得很好。这是我们需要从terminal/cmd

运行的main server.php
require __DIR__ . "/../vendor/autoload.php";
use Chat'Chat;
use Ratchet'Server'IoServer;
use Ratchet'Http'HttpServer;
use Ratchet'WebSocket'WsServer;
$server = IoServer::factory(new HttpServer(new WsServer(new Chat)), 2000);
$server->run();

我用下面的命令从cmd运行这个文件

D:'wamp'www'my_project'api'application'third_party'Realtime'bin server.php

这个命令启动套接字,现在任何用户通过浏览器访问我的网站,然后他们与套接字连接,我可以发送消息给他。当我关闭terminal/cmd时,socket自动关闭。

现在我的开发完成了,我把所有的源代码上传到"openSuse"服务器上。我的问题是如何在服务器上运行server.php文件?(例如amazon ec2 OpenSuse服务器)。因为服务器没有终端/cmd.

这也应该持续运行,所以任何时候任何用户访问我的网站,他们连接到服务器,我会给他发送消息。

我试了很多方法,但都没有用

安装haproxy后,在/etc目录下创建配置文件haproxy.cfg在这个文件中我设置了

backend ws
    server  ws1 my_public_ip:2000
backend www
    timeout server  30s
    server  www1    my_public_ip:80

这里port 2000websocket端口,port 80是我的apache端口我也尝试使用127.0.0.1,但它给出了以下错误

[ALERT] 293/101352 (2291) : Starting frontend public: cannot bind socket [0.0.0.0:80]

跳过这个错误后,我在/etc/目录下创建supervisor.conf文件,并根据给定的链接添加rachet程序在命令中,我给出了server.php文件的完整路径

command = bash -c "ulimit -n 10000; exec /usr/bin/php /srv/www/htdocs/ci_chat/application/third_party/Realtime/bin/server.php"

但是它给了我以下错误

Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.

我的apache运行在端口80上PGSQL运行在5432上现在我不知道哪个服务需要关闭