Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax "Is there new content? If so, update page" - How to do this without breaking the server?

It's a simple case of a javascript that continuously asks "are there yet?" Like a four year old on a car drive.. But, much like parents, if you do this too often or, with too many kids at once, the server will buckle under pressure..

How do you solve the issue of having a webpage that looks for new content in the order of every 5 seconds and that allows for a larger number of visitors?

like image 285
Alexander Morland Avatar asked Nov 14 '08 09:11

Alexander Morland


2 Answers

stackoverflow does it some way, don't know how though.

The more standard way would indeed be the javascript that looks for new content every few seconds.

A more advanced way would use a push-like technique, by using Comet techniques (long-polling and such). There's a lot of interesting stuff under that link.

I'm still waiting for a good opportunity to use it myself...

Oh, and here's a link from stackoverflow about it:
Is there some way to PUSH data from web server to browser?

like image 199
Berzemus Avatar answered Sep 28 '22 08:09

Berzemus


In Java I used Ajax library (DWR) using Comet technology - I think you should search for library in PHP using it. The idea is that server is sending one very long Http response and when it has something to send to the client it ends it and send new response with updated data. Using it client doens't have to ping server every x seconds to get new data - I think it could help you.

like image 26
pbrodka Avatar answered Sep 28 '22 08:09

pbrodka