2016-10-17 74 views
1

我已經實現了帶codeigniter的rachet websocket,它在localhost中工作正常。這是我們需要從終端上運行主server.php /加利福尼亞websocket持久連接到活動服務器

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 

此命令啓動插座,現在任何用戶訪問我的網站通過瀏覽器,然後他們連接到套接字,我可以給他發送消息。當我關閉終端/ CMD時,套接字自動關閉。

現在我的開發工作已經完成,並且我將所有源代碼上傳到「openSuse」服務器。所以我的問題是我如何運行在服務器上的server.php文件? (例如amazon ec2 OpenSuse服務器)。因爲服務器沒有終端/ cmd。

此外,這應該持續運行,所以任何時候任何用戶訪問我的網站,他們連接到服務器,我會給他發送消息。

我嘗試了很多方法,但它不工作。

+1

看這裏:http://socketo.me/docs/deploy –

+0

謝謝@AlokPatel我會實施它,並嘗試解決我的問題,我會在這裏評論如果有關您的給定鏈接的任何問題。 – Jitendra

+0

當然沒問題。 –

回答

0

安裝HAProxy的創建confing文件haproxy.cfg/etc目錄 在這個文件我已經設置

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]

跳過此錯誤後,我創建supervisor.conf文件/etc/目錄和命令添加瑞奇程序按您指定鏈路 下面筆者就給完整路徑server.php文件

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

但它給了我下面的錯誤

在5432 端口80 pgsql的運行

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運行現在我無法瞭解哪些服務需要關閉。