How to run PHP websocket on OVH cloud-web-1 host,

I have a PHP application which uses websockets, When I run it on my local, it works fine, but when I deploy it on my web host, it doesn’t anymore. I am on cloud-web-1 of OVH. I saw that this plan supports websockets. When I launch the PHP server script with SSH, it works fine, but on the client side, when I create a js object socket with url of the websocket ws://ip-address:port or wss or ws://my-domain:port , it never work and it always show error on the browser console like “Connection to websoccket failed.”,

Help me please, Thanks

Did you authenticate it? You can not just access websockets directly. If you are using SSH, is that also set up on your server? You need userid’s and password’s to get into a site that way.

1 Like

Thanks for your answer, How to authenticate a request from client browser ?

You say What sould be set up on my server please ? I don’t understand

Well, a websocket connection is a two-part system. A websocket server and a websocket client.
Therefore, you have to set up your sever to handle websocket connections and then use your PHP script to connect to it. Here is a link for examples of how to connect using PHP. Websocket-client

1 Like

Thank you… But how to set up server so that it can handle websocket ? What I have done is to write a PHP server script.
But from the frontend, I would like to have websocket connection with JS because it should be run without page refresh

Well, you are getting into a complicated system. You need to set up a HTTP:1.1 protocol and a PHP “listener” to monitor client requests. This can be very very complicated. Is there a reason you can’t just use simple Json calls? Might make it much easier for you.

Have you checked the OVH-Cloud’s support site on this subject? Here is a tutorial about this:
Writing Websocket Servers

Sponsor our Newsletter | Privacy Policy | Terms of Service