Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep a websocket server running, even after I close the SSH terminal?

Tags:

php

ssh

ratchet

So, I am using Ratchet with PHP, and have currently uploaded a successful websocket example to my server.

It works after I go to SSH, and then just manually run "php bin/chat-server.php".

What I was wondering is that, in a commercial situation, how do I keep the chat server running?

Thanks.

like image 612
Lucas Avatar asked Oct 21 '13 06:10

Lucas


People also ask

How long can you keep a WebSocket open?

However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.

How do WebSockets stay open?

Unlike HTTP connections, WebSocket connections stay open, or. This is also known as a publish-subscribe messaging pattern: the client can “subscribe” to the server and whenever the server “publishes” a message, the subscribers are notified.

Why does WebSocket disconnect?

WebSocket disconnects can occur for a variety of reasons. Usually, a disconnect means the market data isn't being consumed fast enough. There is a server-side buffer and if it fills, the connection will be delayed and then killed.

Can server close WebSocket connection?

Closing a connection is possible with the help of onclose event. After marking the end of communication with the help of onclose event, no messages can be further transferred between the server and the client.


1 Answers

From the Ratchet Deployment page:

if you are running Ubuntu, fallow these steps:

  1. install supervisor like this: Installing Supervisor

  2. configure ratchet webserver as a service program like this: Supervisor Process Control | Supervisord Install & Usage

making a conf file in /etc/supervisor/conf.d/.conf and fill the conf exmple code from Ratchet Deployment page:

[program:ratchet]
command                 = bash -c "ulimit -n 10000; exec /usr/bin/php /absolute/path/to/ratchet-server-file.php)"
process_name            = Ratchet
numprocs                = 1
autostart               = true
autorestart             = true
user                    = root
stdout_logfile          = ./logs/info.log
stdout_logfile_maxbytes = 1MB
stderr_logfile          = ./logs/error.log
stderr_logfile_maxbytes = 1MB
  1. run the following comands:

    • $ supervisorctl reread
    • $ supervisorctl update
    • and finally check if your service is running: $ supervisorctl

these are all the steps that should be added in Ratched Deployment tutorial.. but this approach may not be the best..

like image 158
Adrian Covaci Avatar answered Sep 28 '22 06:09

Adrian Covaci