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.
However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.
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.
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.
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.
From the Ratchet Deployment page:
if you are running Ubuntu, fallow these steps:
install supervisor like this: Installing Supervisor
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
run the following comands:
$ supervisorctl reread
$ supervisorctl update
$ supervisorctl
these are all the steps that should be added in Ratched Deployment tutorial.. but this approach may not be the best..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With