I am trying to make something like facebook live feeds, for example: when someone likes something or comments on something, the page updates without refreshing it! I want to know which is the proper way to do this? regards
Realtime updates in a web application is a hard problem because a single server handling many simultaneous long-lived TCP connections is a hard problem.
This is essentially impossible on a traditional web server like Apache + PHP because it allocates an entire OS thread for each incoming connection. Threads have significant overhead (like ~2 MB of RAM just for the stack space, plus whatever heap memory your application needs), so as few as a few hundred clients having your page open at the same time can bring a small server to its knees, and even an extra-large (and extra-expensive) hundred-GB-of-RAM server can only handle a few thousand concurrent connections.
Realtime communications is where Node really shines. Its single-threaded, event-driven architecture can easily support 2,000 concurrent connections on a commodity laptop, because each incoming connection is a small (a few kilobytes) heap allocation. The limiting factor actually becomes the CPU and the underlying OS's TCP stack.
My recommendation is to take a look at Node – this is exactly the kind of problem it is designed for. You already know JavaScript, so it's really just a matter of the API and mastering Node's async, event-driven nature.
You'll probably want to use Express for your HTTP server needs and use Socket.io for the realtime communications.
Socket.io is especially wonderful because its client-side library abstracts away all of the drudgery of cross-browser support:
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