views:

94

answers:

3

Say we have users A and B which visit the same URL containing a button. When A clicks on the button, I want something on B's website to change immediately while B is on it, e.g. a text to be added. I want this to happen with a delay of less than 150ms.

Is this realistic? Could you give me hints as to what I should search for, or toy examples which illustrate this? Thanks.

A: 

You can do this easily with php and mysql or some kind of database. Is there something preventing you from using a database? If so you can write to files using php which would let you store these values for user A and B.

jeerose
nothing preventing me. I updated the problem description to reflect that I was searching for a real-time solution.
jacob
+1  A: 

There are 2 main approaches to this:

  1. You can make ajax queries asking if the state has changed every, say, 5 seconds.
  2. HTTP Streaming

This article lists 2 more approaches: http://www.infoq.com/news/2007/07/pushvspull

glebm
Both of your examples are polling. And there are more than these two ways.
Joseph Silvashy
@Joseph fixed both
glebm
I think HTTP Streaming is a take on "HTTP Persistence" which MS pioneered without success in HTML 1 spec. you can still see traces of it in .NET stuff.
Joseph Silvashy
@Joseph, I really want to hire you now. xD
glebm
+5  A: 

I think you should take a look at a Push/Comet server. A very popular one right now is NGINX's push module: http://pushmodule.slact.net/

This is how you can create chat room for example. At least that is what it sounds like you explained.

*update*

As for your latency question, I don't think 150ms is realistic, you realize that it is a full round trip at least plus a DB read and write. Polling will not give you a very snappy experience for the user, this is because your JS might decide to send it's response right before the user completes the action and you'd have to wait until your JS sends the request again for the user "B" to see the update. This could be a long time, maybe like 10 seconds? You wouldn't to use polling in my opinion because it's very wasteful, and makes cacheing pretty tough as well.

I'd go with push. Unfortunately Apache doesn't have a reliable push service like Nginx.

Joseph Silvashy