[英]Facebook live feed functionalty?
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! 我正在尝试制作类似Facebook直播的内容,例如:当有人喜欢某些内容或对某些内容发表评论时,页面会更新而不会刷新! 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 . Web应用程序中的实时更新是一个难题,因为处理许多同时长期TCP连接的单个服务器是一个难题 。
This is essentially impossible on a traditional web server like Apache + PHP because it allocates an entire OS thread for each incoming connection. 这在Apache + PHP等传统Web服务器上基本上是不可能的,因为它为每个传入连接分配了一个完整的OS 线程 。 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.
线程有很大的开销(比如大约2 MB的RAM只用于堆栈空间 ,加上你的应用程序需要的任何堆内存),所以只有几百个客户端同时打开你的页面就可以让小型服务器瘫痪甚至一个超大(而且特别昂贵)的百GB RAM服务器也只能处理几千个并发连接。
Realtime communications is where Node really shines. 实时通信是Node真正发挥作用的地方。 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.
它的单线程事件驱动架构可以轻松支持商用笔记本电脑上的2,000个并发连接,因为每个传入连接都是一个很小的(几千字节)堆分配。 The limiting factor actually becomes the CPU and the underlying OS's TCP stack.
限制因素实际上变成了CPU和底层操作系统的TCP堆栈。
My recommendation is to take a look at Node – this is exactly the kind of problem it is designed for. 我的建议是看一下Node - 这正是它的设计问题。 You already know JavaScript, so it's really just a matter of the API and mastering Node's async, event-driven nature.
您已经了解了JavaScript,因此它只是API的一个问题,并且掌握了Node的异步,事件驱动特性。
You'll probably want to use Express for your HTTP server needs and use Socket.io for the realtime communications. 您可能希望使用Express来满足您的HTTP服务器需求,并使用Socket.io进行实时通信。
Socket.io is especially wonderful because its client-side library abstracts away all of the drudgery of cross-browser support: Socket.io特别棒,因为它的客户端库抽象了所有跨浏览器支持的苦差事:
You can use long polling, yes. 你可以使用长轮询,是的。 Or, you can start to innovate and start using HTML5's connectivity capabilities and REALTIME the sh*t out of your site.
或者,您可以开始创新并开始使用HTML5的连接功能,并实现您网站的实时性。 There are already several out-of-the-box solutions for that, my favourite being the xRTML Realtime Framework .
已经有几个开箱即用的解决方案,我最喜欢的是xRTML Realtime Framework 。
Check it out 看看这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.