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.
The ratchet documentation has a deploy page. Did you checked it?
Old answer: It may be a bad idea on a prod server (this is a personal assumption), but you can use the
screen
command to open a terminal, launch your daemon, then press Ctrl-A, Ctrl-D, and your terminal is still alive, opened in background. To reconnect to this terminal, connect back to your server and typescreen -r
.Start it in
/etc/rc.d/rc
for *nix servers. This should launch your PHP script whenever the server boots.I don't actually know about how the industry does it, as I am just a programming/linux hobbyist and student right now, but that's the route I would go on a personal server.
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:
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..
Make a daemon.
If you are using symfony2, you can use the Process Component.
If you are using native PHP, never fear,
popen
is your friend!There are of course also other helpful PHP libraries for working with daemons. Googling "php daemon" will give you a lot of pointers.
This tutorial shows a really cool way of turning the WebSocket into a *nix Service to make it persist even when you close your SSH connection.
Basically you make a file
/etc/init/socket.conf
with the following contentsBlog Post:
http://blog.samuelattard.com/the-tutorial-for-php-websockets-that-i-wish-had-existed/