How can I implement a realtime dashboard?

荒凉一梦 提交于 2019-12-11 07:39:50

问题


I would like to implement a realtime dashboard like an index page of www.foursquare.com

I checked foursquare.com's index page with Chrome's developer tool and surprised that they don't use xhr to get those information approx. every 5 seconds.

Using ajax polling causes memory leak in some browsers and make a server busier.

Is there any way that I can implement a realtime dashboard efficiently with PHP and jQuery(AJAX)?

(Perhaps I need an extra server something like a push server?) :|


回答1:


Foursquare's homepage loads 30 items (id=recent29, id=recent28, ...) but displays only 11 at once. So you will have a real-time feeling for about 90 seconds (after that, the same items reappear).

...
$('#recent'+toShow).slideDown(1000, move(i));
$('#recent'+i).slideUp(1000, move(i));
...

For some bidirectional client server communication, take a look at websockets, even though they are not universally supported yet, they eventually become a standard.

The WebSocket API is being standardized by the W3C, and the WebSocket protocol is being standardized by the IETF.




回答2:


One method to get data pushed to a client is a loop like this:

  1. Open AJAX request in browser.
  2. Server waits with the request open until it either times out or new data is available.
  3. Server returns the request with either new data or a timeout, and client immediately opens a new request.



回答3:


You could use comet, APE is particularly easy to setup and configure:

http://www.ape-project.org/

Back-end is written in C so it's very fast.



来源:https://stackoverflow.com/questions/6935016/how-can-i-implement-a-realtime-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!