hno Posted February 28, 2012 Share Posted February 28, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257917-need-idea/ Share on other sites More sharing options...
scootstah Posted February 28, 2012 Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257917-need-idea/#findComment-1322024 Share on other sites More sharing options...
Psycho Posted February 28, 2012 Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257917-need-idea/#findComment-1322034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.