While reading the Brain Socket's documentation I read the following:
Any changes to your laravel app / code while the ws server is running are not taken into account. You need to restart the ws server to see any of your changes.
I understood why that's needed, but since it quite inconvenient to CTRL+C and executing php artisan brainsocket:start every time, what would be a convenient way to restart the websocket server?
Related
I want to set up a WebSocket server using PHP. I have many alternatives to do this, yes, but I wanted to ask people who have experienced which one is more reliable (strong, lightweight, and faultless). I also wrote some code, this code creates a socket server, but I'm not sure how to start it, do I need to open the page from the browser?
Usually a web socket server, as many servers, is started to operate as a daemon in the background and listen there for events coming in. On Linux (Ubuntu) you might create a unit file to be consumed by the system command systemctl, this way the daemon will be started with every boot of the system and you can start and stop it as you need to.
Next you can start it form a command shell like
nohup php websocketserver &
This will send your server into the background an stay there until the system is rebooted. Any output is logged to a file named nohup.
On Windows you better create a service, via a schedule task to have your server start at system boot.
I am using the ratchet websocket server on CentOs. The problem is it is stopped after some time. I have used the screen command to solve the problem but when server is rebooted it does not start automatically. Is there any way to start the websocket server automatically when it was stopped or killed or server was restarted?
You can use supervisord for it.
It can monitor and automatically start / restart processes.
I am really sorry for my Poor English.
I have created simple websocket game with voryx/ThruwayBundle for Symfony. Game uses RPCS registered on Server. Everything works fine but when I leave for about 20 mins RPCS are no longer available. And I have to restart websocket server to make them avaiable again.
I tried to register my rpcs as workers and I can see them running but they are still unavailable
websocket server process status
The annotation I use to register RPC is
/**
* #Register("games.snake.newplayer",serializerEnableMaxDepthChecks=true, worker="add-snake")
*/
I run server with command
nohup php app/console thruway:process start &
You can see it on http://amusement.cloudapp.net/
I am using Ubuntu 15.10 server created in Microsoft azure if it's any help
I don't know what I can do to make those RPC available anytime without restarting websocket server. Should I make some cron action to reset websocket server if they're stopped responding and how can I do it.
Edit#1
RPCS work great on my local machine Ubuntu 14.04
To prevent disapeearing of rpcs I created symfony console command to ping them with some test data. Next I registered this command as cron job to be executed every minute.
I could't find the source of problem however it's easy way to avoid it.
I'm new to Laravel/Composer and MVC frameworks in general. I've been going through some very good tutorials but in my development environment, each time I run
php artisan serve
in terminal and then make an HTTP request, the development server process is killed. The log doesn't record any errors at the time the request is made or the process is killed. This issue seems similar and is the only other thing I could seem to find, but for me the issue is happening on a fresh install and I'm not invoking the Sentry call anywhere (it even occurs when i request a simple static html or image file). Is there something I need to do to keep the server running after a request is made?
Thanks so much!!
is there a way how to easily run a PHP application as from command line on Windows Azure?
I have a standard Web Application (on Azure) and I want to communicate using WebSockets.
So I need to have a WebSocket Server running all the time on Azure.
I use Wrench project which I need to run "all the time" to listen on some port and deal with messages from JavaScript-sended WebSocket.
So again - how easily run a "persistent" PHP application on Azure?
Thank you in advance.
Sandrino's answer is fine, but I prefer ProgramEntryPoint for doing this sort of thing. The trouble with a background task is that (unless you build something on your own) nothing is monitoring it. Using ProgramEntryPoint, Windows Azure will monitor the process, and if it exits for any reason, the role instance will be restarted.
EDIT:
Sandrino points out that the PHP program isn't the only thing running. (There's also a website.) In that case, I'd recommend launching php.exe in Run() in WebRole.cs. Process.Start it and then do a .WaitForExit() on it. That way, if the process exits, the role itself will exit from Run(), causing the role instance to restart. See http://blog.smarx.com/posts/using-other-web-servers-on-windows-azure for an example.
In order to run your PHP script as a command line application you should use the PHP CLI (command line interface).
php.exe -f "yourWebSocketServce.php" -- -arg1 -arg2 -arg3
Now, in order to run this in Windows Azure you'll need to define a startup task that runs this command. You'll see that the default task type is simple, which means that the startup of your role will block until the task finishes. But in your case running the WebSocket in PHP will be a blocking process, that's why you should change the type to background (this will make sure the instance continues starting up while your WebSocket server is running).
Here is a WebSockets service on Azure. - Live XSockets.NET
Have a look at http://live.xsockets.net, an easy way of getting started, but it depends on what you are about to do on the "server side". This service i mention can be uses as a "message" dispatcher, to ntify "clients" on changes etc.. Hmm in other words it is a way of boosting "regular" web-apps..