What exactly does setting up a PHP Websocket server mean?

Now I get into Web Sockets and have successfully used the online ports of Pusher (he did not like it) and Scribble (surprisingly, the downtime is too often, since it works only by one person).

I followed this tutorial http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/ on my localhost and it works great!

I wanted to ask how can I configure server.php from the above file to run as a web server server on a web hosting / shared server?

Or do I need to get a VPS (and if so, which one do you recommend and how can I configure the websocket server there since I have never used VPS before!)

Thank you for reading my question and answering. I read all the other questions / answers here regarding sockets, but so far I have not been able to find the answer to my previous questions. Hope i find it here!

+6
source share
1 answer

It's complicated.

You need to execute the server.php script and it never needs to exit. If you have access to SSH on your shared server, you can execute it in the same way as in the screenshot and run it as a background task using something like nohup :

 $ nohup php server.php nohup: ignoring input and appending output to `nohup.out' 

After calling this (using an SSH connection), you can exit and the process will continue. All script fingerprints will be stored in nohup.out , which you can read at any time.

If you do not have access to SSH, and the only way to execute a PHP script through Apache as a result of requesting a page, you can simply go to this page using a browser and never close the browser. But one day there will be some kind of timeout, and the connection between you and Apache closes, effectively stopping the execution of the server.php script.

And in these previous cases, many shared hosts will not allow the script to run indefinitely. You will notice that this line is in server.php :

 set_time_limit(0); 

This tells PHP that there is no time limit. If the host started PHP in safe mode (which many of them do), then you cannot use set_time_limit , and the time limit is perhaps 30 seconds or even less.

So yes, VPS is probably the best choice. Now I don’t own it myself and I don’t know what the good / bad price is, but I would say HostGator seems fine.

+4
source

Source: https://habr.com/ru/post/947357/


All Articles