what is the best way to implement real-time notifications on a shared hosting Server-Sent Events(SSE) or long polling?
I watched a video which said SSE is not suitable for shared hosting, Apache server and does not go well with PHP and MySql.
I just want to know which technique will be more suitable long polling or SSE for real time notification on a shared server, I have my server on godaddy.com
Please provide good links explaining the recommended technique.
Each SSE connection holds open a dedicated socket. If you are using Apache and PHP then there will also be an instance of those in memory. They are sitting there, hogging memory, even if you never send any data to the clients.
The economics of shared hosting relies on the idea that most users are not loading the servers, most of the time. If you start holding apache processes in memory all the time, your ISP will go round killing those processes. For instance, BlueHost appear to have a script that automatically seeks-and-destroys long-running processes; I'm imagining GoDaddy has the same.
Beyond that, an ISP might put a caching proxy server in front of your websites, which will disturb SSE and long-poll. (In this case you might be able to send special headers to the proxy to tell it not to.)
So, there is no technical reason SSE and long-polling cannot be used with shared hosting, but in reality your ISP will try to stop you.
For the other part of your question, SSE and long-polling are basically the same; SSE gives you a built-in JavaScript API, and is a bit more efficient. Use SSE when the user's browser supports it, otherwise write your own long-poll routine.
If you are tied to shared hosting, I recommend going with short-polling (i.e. an AJAX call every 15 or 30 seconds). You add a bit of latency, but save a bit of money.