The best way for instant messaging without Websockets

I have a web server that I am currently taking off the host. They don't let you use webrtc or node.js or anything like that.

I have a messaging system using PHP / SQL / Ajax (when a user views a message stream, it fetches new data every 60 seconds), but it doesn't seem instant, and it also doesn't seem to be very server friendly if there are many users ...

So my question is, is there a way I can live - update data for my users without having to constantly request new data and without having to use websockets?

I would like to implement this with notifications and comments, so having a lot of ajax scripts requesting data every x seconds doesn't seem like a good idea.

+3


source to share


1 answer


Personally, I suggest that the best solution to your problem is to use websocket

. This is the most efficient way so far. And in this regard:

They do not allow webrtc or node.js or anything like that.

You can find some kind of hosting that will allow you to run websocket servers. For example https://www.digitalocean.com where you can set up / install your own socket server on the hosting.

I have a messaging system using PHP / SQL / Ajax (when a user views a message stream, it fetches new data every 60 seconds), but it doesn't seem instant, and it also doesn't seem to be very server friendly if there are many users ...

I think this method that you are using now is now AJAX Polling

where you continually query every interval for new updates to the database. This is fine for minimal updates, but I personally don't recommend using this method. Each request per interval affects the speed and performance of your application in the long run. This is why you are correct:

I would like to implement this with notifications and comments, so having a lot of ajax scripts requesting data every x seconds doesn't seem like a good idea.



And this:

So my question is, is there a way I can live, update data for my users without constantly asking for new data and having to use web files?

Yes, there is a way to use SSE (Server Sent Events) . See example from w3fools: D .

But just in case, if you look at websockets again, you can try websocket for PHP: Ratchet .

Also check this out: Ways to Request / Get Live Updates for a Web Application.

+4


source







All Articles