Jump to content

Need idea


hno

Recommended Posts

HI,

I'm writing a auction website .in auction website we need to check for new information every second so it needs to be ajax.

we have a timer which calculate the end time of every auction and it needs to be updated every second.Do you have any idea for reducing the process of calculating maybe a client side but something that is updated by server?

I mean , the timer works with client side and when the users BID , the timer needs to be refresh.So every time that Bid button hilted the time should be refresh.

What's you idea?How can do something like that?

 

Thanks

Link to comment
Share on other sites

When you save the bid, just update the date that is saved in the database. Here's a quick example...

// get item id
$item_id = $_POST['item_id'];

/*
* ... code to save bid ...
*/

// update items remaining time
$query = "UPDATE items SET time_left = time_left + INTERVAL 15 SECOND WHERE id = '$item_id'";

mysql_query($query);

 

Then you can use Javascript/AJAX to change the time shown on screen.

Link to comment
Share on other sites

Not really understanding your request.

. . . idea for reducing the process of calculating maybe a client side but something that is updated by server?

 

If it is updated by the server, then the server is doing the work. The solution is to simply make your calls as efficient as possible. There are a few things you can do to that end.

 

Let's assume that the user is on a specific auction page for an item and you want to update the current status of the auction for that item to the user in as near real-time as possible.

 

First of all, you can never guarantee that a call to the server will complete within 1 second. So, you should make the AJAX call synchronous - i.e. let one call complete before another is called. Otherwise, if there is is a delay in the user's internet connection or a server lag it could cause all the requests to pile up.

 

Second, you should send/retrieve only the minimal information needed. For an auction page the AJAX request should only need the auction ID (however, I'll discuss another parameter later). The return value should only need to return a "false" value if there were no changes or, if there were changes, just the minimal information of what changed (new bid, current high bidder). Plus, do not format large section of HTML on the server and return it to be updated. Instead, just return the necessary values (or only do minimal formatting) and use the JavaScript to update the content on the page.

 

Third, use a timestamp to prevent unnecessary processing. The first time the page is loaded (or the AJAX call is made) generate a timestamp on the server and include it in the response. The AJAX call will include the timestamp on every subsequent call to the server. In the server logic you would use that timestamp when querying the data for the status of the item using something such as

SELECT bid_price, bid_user
FROM auctions
WHERE auction_id = $id
  AND last_updated > $timestamp

 

So, if the status of that auction item has not changed you will get no results and you can simply return a false to the AJAX call. This cuts down on the processing that would be needed when there have been no changes.

 

Those are just a few ideas off the top of my head.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.