The most important part is that the message must be sent to an existing socket, which means that you cannot call socket_connect, fsockopen or any other function in PHP that will try to make an unsolicited connection to the client. This is not a thing of the web cluster - it is a fundamental concept of network programming.
In phpwebsocket, it will be something like this:
$msg = "hello world"; $phpwebsocket->send($user->socket, $msg);
where '$ phpwebsocket' is the PHP WebSocket object, $ user-> socket is the connected user who connected to priory using javascript WebSocket (), and send () is the method in the WebSocket object that will correctly encode the message into a frame ( or should be as soon as possible).
However, if for some reason you want to connect to the websocket server using websockets from PHP, you need to check https://github.com/nicokaiser/php-websocket . The server in the link will not make any difference if you are happy with your current solution, but the package also contains the PHP Websocket client class that you need.
source share