Usually, if you want to write a socket server in PHP, you need to run it through the command line. What you would like to take into account is the following:
You need access to sockets that are usually not on the shared server, so you will need to get a VPS.
You want to set up a file on your server that automatically runs your PHP script every time the server restarts. This is usually done by placing a shell script that runs a PHP script in /etc/init.d and then places a symbolic link in a shell script in / etc / rc 5.d (assuming your level is the default).
You also most likely do not want / should not start Apache unless you plan to use this server as a file server. If you use it exclusively for the socket server, you must install the PHP-CLI. It will save your memory.
If you are trying to interact in real time between users connected to your server, you may not want to turn on the database at all. Your socket server will have a list of all subscribers connected to the socket server, so when one of them sends you a message, you can immediately send this message to all connected subscribers without saving anything in a slow database. In addition, you would like to keep the information in your memory if you can afford it.
There is a solution for sockets that are not supported in all browsers called socket.io. Basically, I believe that he is trying to configure the browser website if it is supported, but if it is not supported, it starts a flash connection. In any case, you use the same interface to interact with it.
You can also consider another language for creating your socket server. PHP is not designed for this type of thing. Javascript will be the best language to use, especially if scalability is a problem. Node.js is a library that will allow you to easily create a socket server and will be much more scalable.
source share