1

I want to create a bidding system where user can see the current price of items. And if any other user on any other location place a bid before me it should auto update bid in my browser.

I have read about autoupdate JS+Ajax functions but even if I place a 5 second timer to auto update the content on user's browser will it not put some extra load on server by making an ajax call every 5 second? Its a bidding system so user will have bids updating within 1-2 seconds so if i put an auto update ajax call for every 1-2 seconds it will put a lot of burden on server.

So I am wondering is there any better way to handle this type of stuff? how do twitter/facebook do update user's feeds?

Inam Abbas
  • 1,480
  • 14
  • 28
  • 1
    Take a look at this answer - http://stackoverflow.com/a/7132828/295508 Server push methods or some kind of web socket system should work for you – JohnP Feb 12 '12 at 13:18

3 Answers3

3

AJAX or not, bidding systems always have high requests because people keeps refreshing the page to check for the latest bid information.

You can take a look and attempt long polling. Long polling a method where you "push" data from the server to the browser in response to the browser's HTTP request. It is a normal HTTP connection. This may reduce the number of requests sent from users to server, however you will still have many open and active connections between your users and your server.

Community
  • 1
  • 1
mauris
  • 42,982
  • 15
  • 99
  • 131
1

You will want to look at long polling. In essence, this is how it works

  • On the server you need some sort of event mechanism (no probem with PHP)
  • Client (Browser) starts an AJAX request referencing a bidding item
  • Server checks for changes on the bid, if there is one, returns the request
  • If not, he waits for some time (minute range), waiting on an event concerning this bid
  • If such an event occurs, server returns the request with the info, if not he returns the request with "no bid" info
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
1

You might be able to get away with a streaming model...

Each JS client connects to the server once and keeps the conneciton open. As new events arrive at the server, they are broadcast to all the open connections in real time.

This is similar to the mechanism twitter uses to broadcast tweets.

Basic
  • 26,321
  • 24
  • 115
  • 201