Real-time updating 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
mrausch
Forum Newbie
Posts: 1
Joined: Thu Jan 14, 2010 2:56 pm

Real-time updating website

Post by mrausch »

Hello,

I need to build a website that updates in real time, but I do not know what the best way to implement a solution that will allow me to do this. I have a program which constantly checks for new pricing data from an exchange and then writes this data to a mysql table. I would like to build a website which will display this data and be up to date. Ideally any new data would be 'pushed' and immediately reflected on the website but I would also settle for a slightly less ideal solution if it's significantly easier to implement. Can anyone suggest how I should go about solving this problem and what tools (php, javascript, ...) would be best applicable for each part?

Thanks,

Max
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Real-time updating website

Post by Christopher »

If the data is in MySQL then all you need to do is fetch it with PHP and generate HTML to send to the browser. Check the manual for PDO for code examples.

You may want to investigate setting the HTTP headers so the page(s) are not cached by the browser. That way users get the latest data.
(#10850)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Real-time updating website

Post by califdon »

I wonder if Max doesn't mean a real-time updating after the page has been loaded into the browser. In that case, he needs to use AJAX and a Javascript loop that refreshes the data at a specified interval (seconds, or minutes, or whatever).
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Real-time updating website

Post by josh »

( or just put a meta refresh tag in your html header)
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Real-time updating website

Post by arjan.top »

josh wrote:( or just put a meta refresh tag in your html header)
that's not really real-time
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Real-time updating website

Post by califdon »

arjan.top wrote:
josh wrote:( or just put a meta refresh tag in your html header)
that's not really real-time
Why isn't it? If you put a 1 second refresh time, I'd call it pretty close.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Real-time updating website

Post by josh »

arjan.top wrote:that's not really real-time
Neither is ajax, the client has to post a request to the server, an electrical signal leaves the client computer and goes halfway around the globe and back, plus factor in the time it takes the client computer to process the ajax response. Even "live" tv is not really live, not even close.

Ajax is the same thing from the user's opinion. Unless the surrounding XHTML is heavy weight. Easy solution: iframe

But yeah ajax wouldn't be a bad way to do it though.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Real-time updating website

Post by arjan.top »

did not say ajax is real-time (but hame some tricks to get almost real-time)

comet (ajax push, HTTP streaming, server push or. any other name) is the closest to real-time we can do right now (WebSocket should solve that)

the idea is that server dows push the data to the client when it is avaliable
Post Reply