Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Auction Timer help

    Hi everyone,

    I've had a mess around with java at college and can get my head around code pretty easily but I cant seem to fnid out how to get a Javascript timer to work.

    The timer is like the one of Swoopo where it counts down to zero.
    When a user places a bid it should add on time such as 10 seconds.

    First of all what would be the best way of running a timer? A cron-job?
    Next problem is adding the time and getting it to update in everyones browser

    I have checked other posts on here but the posters seem to know the basics of my problems but Im not sure I do.

    any help would be appreciated
    Last edited by rmail2006; 09-06-2010 at 12:26 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Next problem is adding the time and getting it to update in everyones browser
    The HTTP protocol is *STRICTLY* a "pull" protocol. The client (e.g., the browser) make an HTTP Request and the server makes an HTTP Response. And that's it. One time request/response and then each forgets about the other.

    So you CAN NOT "update in everyones [sic] browser" by "pushing" data to those other browsers.

    And you ask if running a CRON job is the best way to run a timer: Ummm...CRON doesn't exist in Windows. And 95% of your browser users will be running Windows (or perhaps a phone client, which also won't support CRON).

    So maybe if you explained WHAT you are trying to do we could help. Maybe other people will understand this, but I sure don't:
    The timer is like the one of Swoopo where it counts down to zero.
    When a user places a bid it should add on time such as 10 seconds.
    Add on time where? To what clock? Why 10 seconds? What's "Swoopo"?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    When the page is served initially, the server-side code must calculate the remaining time and use that value to initialise the JavaScript timer. If the expiry time is subject to deferral, the JavaScript countdown timer must poll the server periodically to check for a change in expiry time, and if necessary harmonise its displayed time.

  • Users who have thanked Arty Effem for this post:

    rmail2006 (09-07-2010)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Old Pedant View Post
    What's "Swoopo"?
    Try Google! But I don't understand why the remaining time should change when someone makes a bid.

  • #5
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the replies evryone

    And you ask if running a CRON job is the best way to run a timer: Ummm...CRON doesn't exist in Windows. And 95% of your browser users will be running Windows (or perhaps a phone client, which also won't support CRON).
    What I was thinking is the timer would be in te mysql table for a certain item whic would store the seconds remianing. The server would be running the cron-job updating the mysql feild taking 1 second of each time it is run which would be every second until it counts down to zero.

    Add on time where? To what clock? Why 10 seconds? What's "Swoopo"?
    Once the timer is below say 10 seconds then when a bid is placed it should add 10 seconds onto the items timer in mysql.

    I understand how to add and update mysql but I'm not sure how to use mysql with javascript, updating every click without resetting the page.


    Arty, that sound like a great way to save the server a lot of abuse by using a timer to set a check time compared to checking every second.
    How would you set up a timer in javascript which would send a request to the database when its at a certain value?

    Philip, why the time changes if the user bids is to let people battle for an item as long as they can until someone drops out. So within the last 10 seconds a bid would increase the timer by 10 seconds say, which gives a chance for someone else a bid and it stops people from waiting till the last seconds and trying to, as ebay says, snipe it.

    Again Thanks everyone.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    OKAY! Makes more sense.

    But there's no need to update the time in MySQL until/unless a bid is made.

    Instead of storing the seconds remaining, just store the time the auction expires. When a user hits the page, you get the expires time from the DB and the server time from the server and *THEN* send the time remaining (either as seconds or a HH:MM:SS or whatever) to the user's browser.

    And, yes, if somebody makes a bid you can add 10 seconds to the expire time.

    But remember what we said: *OTHER* users/customers will *NOT* see the expires time change by those 10 seconds *UNLESS* you have their browsers "poll" the server to get the updated time remaining. Sure, you could do that with AJAX. But unless you have a pretty powerful server, it wouldn't take too many clients hitting it every few seconds to take it to its knees.

    Given that you are coding this yourself, I have to guess that you will be running on a budget, and that probably means a shared hosting web server. Which means that they aren't going to be happy with you trying to have, say, 100 users hitting the server every second just to get updated expires time.

    I think you *probably* could get away with this by making a couple of compromises: (1) change it form 10 seconds to maybe a minute. (2) Only if a user has made a bid on an item do you use AJAX to go out and get update expires time and even then you only do it once every 10 or 15 seconds. Any non-bidders only get updates every minute.

    I think that would keep the server load on a shared host down to a probably acceptable level. Then, maybe later, if and when you get more successful and can afford your own dedicated hosting with multiple servers, you could change to your ultimate goal of 10 second "bumps" and 1 second AJAX requests.

    What do you think?

    p.s.: Note that none of this will be perfect. A user's browser could hit the server and find there are 37 seconds remaining. But, just because of network delays and/or browser rendering times, the user's JavaScript timer doesn't start firing for, say, 4 seconds. So the user thinks he has 37 seconds and he really only has 33. Even with EBay, I used to have this happen to me when I had a slower connection than I have now. I'd occasionally hit the "BUY" button with as much as 10 seconds remaining only to be told the auction had closed. Hasn't happened in last 2 or 3 years since EBay upgraded and I got faster connection, but treat that as fair warning. The internet is *NOT* instantaneous, however much it often seems that way.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    rmail2006 (09-07-2010)

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Old Pedant View Post
    But remember what we said: *OTHER* users/customers will *NOT* see the expires time change by those 10 seconds *UNLESS* you have their browsers "poll" the server to get the updated time remaining. Sure, you could do that with AJAX. But unless you have a pretty powerful server, it wouldn't take too many clients hitting it every few seconds to take it to its knees.

    That will not work surely. If bidder A makes a bid his time will have 10 seconds added, but bidder B who has not yet made a bid will think that the remaining time is 10 seconds less and the auction is over. Sounds a recipe for chaos to me!

    The idea of keeping adding 10 seconds to the time is to encourage people to fight it out in the final seconds - but it costs them $0.65 to make a bid, whether the bid is successful or not.

  • Users who have thanked Philip M for this post:

    rmail2006 (09-07-2010)

  • #8
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts
    p.s.: Note that none of this will be perfect. A user's browser could hit the server and find there are 37 seconds remaining. But, just because of network delays and/or browser rendering times, the user's JavaScript timer doesn't start firing for, say, 4 seconds. So the user thinks he has 37 seconds and he really only has 33. Even with EBay, I used to have this happen to me when I had a slower connection than I have now. I'd occasionally hit the "BUY" button with as much as 10 seconds remaining only to be told the auction had closed. Hasn't happened in last 2 or 3 years since EBay upgraded and I got faster connection, but treat that as fair warning. The internet is *NOT* instantaneous, however much it often seems that way.
    This was a big problem I also noticed but theres not much can be done about it lol

    I would have to keep every browser in sync as much as possible as it would cause a lot of bother but as you said 10 seconds is a bit too low.

    I'm goin to try out a javascript timer like Arty said in post 3 which will be set when the page is loaded. and instead of adding 10 seconds I might just keep ressetting it to a minute when a bid is made. I've got a few ideas Im goin to try, ill repost when im done just to help others incase theyve got the same problems

    Thanks for your help everyone

  • #9
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sync Timer

    I have done a few tests with ASP.NET(C#) and PHP, also using AJAX/jQuery and the main deal seems to be the amount of work caused by the requests(every second/every client) to the server.

    I am not a specialist when it comes to infrastructure but I bet this type of system will only work with some investment on at least one good server with a very fast internet connection.

    Does anyone else have more details?


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •