I have a webserver that I'm currently renting from a host. They don't allow webrtc or node.js or anything like that.
I have a messaging system using PHP/SQL/Ajax (When user's viewing the message thread, it fetches new data every 60 seconds) but that doesn't seem instant and also seems like it's not very convenient for the server if a lot of users are on.
So, my question is: Is there any way I can live-update data to my users without having to constantly request new data and not having to use websockets?
I'd like to implement this with notifications and comments as well, so having a lot of ajax scripts requesting data every x amount of seconds doesn't seem like a good idea.
WebTransport is a new specification offering an alternative to WebSockets. For applications that need low-latency, event-driven communication between endpoints, WebSockets has been the go-to choice, but WebTransport may change that.
If you have major concerns about security, then XMPP is the protocol for you. If you require built-in presence and messaging functionality, XMPP is your best choice. If data transmission speed is a top priority, then WebSocket is the protocol you're looking for.
However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.
Yes it is. In fact, a chat is the single most common example of web socket application.
XMPP is used in WhatsApp, GTalk, and Grindr applications and inbuilt in the chat features. To be specific, the protocol is mostly preferred where one-to-one secure or group-based communication is the main feature of the app. Trello, Slack, and Discord are the three most famous apps built using WebSockets.
Personally, I suggest that the best solution to your problem is to use websocket
. That's the most effective way so far. And regarding this:
They don't allow webrtc or node.js or anything like that.
You can find some hosting that can allow you to run websocket servers. Like for example https://www.digitalocean.com where you can setup/install your own socket server in the hosting.
I have a messaging system using PHP/SQL/Ajax (When user's viewing the message thread, it fetches new data every 60 seconds) but that doesn't seem instant and also seems like it's not very convenient for the server if a lot of users are on.
I think this method you currently use right now is AJAX Polling
where you persistently request on every interval for new updates in the database. This is okay for minimal updates but personally I don't recommend using this method. At every request per interval is affecting your app speed and performance in the long run. That's why you are correct:
I'd like to implement this with notifications and comments as well, so having a lot of ajax scripts requesting data every x amount of seconds doesn't seem like a good idea.
And this:
So, my question is: Is there any way I can live-update data to my users without having to constantly request new data and not having to use websockets?
Yes, there a way using SSE (Server-Sent Events). Check an example from w3fools :D.
But just in case you consider websockets again, you may try websocket for PHP: Ratchet.
Also check this out: Ways to make request/get realtime updates for a web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With