How to implement "Real-time" event updates on a website

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
emmbec
Forum Contributor
Posts: 112
Joined: Thu Sep 21, 2006 12:19 pm
Location: Queretaro, Mexico

How to implement "Real-time" event updates on a website

Post by emmbec »

Hi guys, I was wondering if anyone of you know how to implement something similar to what the guys from nailbidder.com have in regards of updating the current bid. It looks like as soon as someone performs a bid, the price gets updated and the time remaining for the bid also gets updated (Once a bid is close to ending). How do they do that? I mean, how can they update the bid status and everything when someone else other than the person who is viewing the website is submitting information? Specially the time, since they are showing seconds and it looks like it never gets too de-synchronized from what I see...

Thanks!
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: How to implement "Real-time" event updates on a website

Post by Technical »

Most likely they use JS framework to periodically requesting information with AJAX requests. Prototype framework has special class for it - Ajax.PeriodicalUpdater
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: How to implement "Real-time" event updates on a website

Post by Technical »

They key is using setTimeout() method.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: How to implement "Real-time" event updates on a website

Post by Jonah Bron »

Technical wrote:They key is using setTimeout() method.
Actually, setInterval would be better. For the bidding, just use setInterval to periodically call the server asking for the latest bid. For the time, just keep the time with the client's clock, and re-synchronize at the same time as when you update the bid.

But beware, do not use setInterval/setTimeout for the clock; it slowly becomes incorrect.
Post Reply