Facebook feed functionality?

I'm trying to do something like direct news on facebook, for example: when someone likes something or comments on something, the page refreshes without updating it! I want to know what is the right way to do this? considers

+6
source share
2 answers

Real-time updates in a web application are a complex problem, because a single server serving many simultaneous long-lived TCP connections is a difficult problem .

This is almost impossible on a traditional web server such as Apache + PHP, because it allocates the entire OS thread for each incoming connection. Threads have significant overhead (for example, ~ 2 MB of RAM for the stack space only, plus any heap memory your application needs), so the several hundred clients that open your page at the same time can put a small server on their knees, and even a very large (and very expensive) server with one hundred GB-RAM can handle several thousand simultaneous connections.

Real-time communication is where Node really shines. Its event-driven, single-threaded architecture can easily support 2000 concurrent connections on a commodity laptop, since each incoming connection is small (a few kilobytes) heap distribution. The limiting factor is actually the processor and the underlying TCP stack of the operating system.

My recommendation is to take a look at Node - this is exactly the problem for which it is intended. You already know JavaScript, so it really is an API issue and event driven Node async mastering.

You will probably want to use Express for your HTTP server needs and use Socket.io for real-time exchange.

Socket.io is especially remarkable because its client-side library abstracts all the hard work of cross-browser support:

  • In A-grade browsers , it connects to your server via WebSockets . This gives you a TCP socket that remains connected indefinitely, on which you can click arbitrary data at any time.
  • In lower level browsers, it uses a fallback mechanism:
    • Flash-based vehicles, such as WebSockets, but which require a Flash player (if any)
    • AJAX Long Survey
    • And a few more esoteric backups if none of them work
+11
source

You can use a lengthy survey, yes. Or you can start innovating and start using the HTML5 and REALTIME sh * t connectivity features on your site. There are already several ready-made solutions for this, my favorite is the xRTML Realtime Framework .

Check out

+1
source

Source: https://habr.com/ru/post/907621/


All Articles