最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Facebook live feed functionalty? - Stack Overflow

programmeradmin1浏览0评论

I am trying to make something like facebook live feeds, for example: when someone likes something or ments on something, the page updates without refreshing it! I want to know which is the proper way to do this? regards

I am trying to make something like facebook live feeds, for example: when someone likes something or ments on something, the page updates without refreshing it! I want to know which is the proper way to do this? regards

Share Improve this question asked Feb 3, 2012 at 23:38 Sabri AziriSabri Aziri 4,1745 gold badges32 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

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 ining 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 munications is where Node really shines. Its single-threaded, event-driven architecture can easily support 2,000 concurrent connections on a modity laptop, because each ining connection is a small (a few kilobytes) heap allocation. The limiting factor actually bees the CPU and the underlying OS's TCP stack.

My remendation 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 munications.

Socket.io is especially wonderful because its client-side library abstracts away all of the drudgery of cross-browser support:

  • In A-grade browsers, it connects to your server via WebSockets. This gets you a TCP socket that remains connected indefinitely, over which you can push arbitrary data at any time.
  • In downlevel browsers, it uses a fallback mechanism:
    • A Flash-based transport like WebSockets, but requires Flash player (if available)
    • AJAX long polling
    • And some more esoteric fallbacks if neither of those work

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. There are already several out-of-the-box solutions for that, my favourite being the xRTML Realtime Framework.

Check it out

发布评论

评论列表(0)

  1. 暂无评论