开发者

How can I implement a realtime dashboard?

开发者 https://www.devze.com 2023-03-24 22:05 出处:网络
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

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 t开发者_开发百科hat I can implement a realtime dashboard efficiently with PHP and jQuery(AJAX)?

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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消