skip to Main Content

Basically i just want to know if i have the right idea or if a better one exists.

I have a database that stores auctions that are currently taking place on the website (or will do). Obviously there comes a point when the auction will end. I am pretty new to web developing and was just wondering the best way of changing the status of the auction in the database to “expired”.

I am using phpmyadmin and mysql and have read a bit about mysql event schedulers. From what i can gather they seem like a good way of doing this. On this basis i surely just run a recurrent event every minute, say, and it checks the current time against the preordained finish time of the auction and then makes changes if need be? Is this correct? Also i can then move the expired auctions to an old archive – probably the best right idea do you think for optimum performance of my database?

Otherwise i just wondered if there was a better (or easier way) of doing the same thing. How do sites like ebay go about it for example? Thanks a lot for your time in advance.

P.S. I realize this is more of a conceptual question then anything specific. Nevertheless i hope its alright to ask!

2

Answers


  1. You’re way overcomplicating this. You don’t need to actually change the status of the auction the moment it expires. The status is self-explanatory already from its expiry date. If you have a column expiry_time in the database, any time before that the auction is active, any time after it’s expired. As simple as that. Use appropriate queries, like this to find all active auctions:

    SELECT * FROM `auctions` WHERE `expiry_time` > NOW()
    
    Login or Signup to reply.
  2. You could do it this way, but I would suggest another approach. This is something I’ve implemented myself (in a game, but with the same mechanics), and it worked like a charm.

    The only thing you have to do is to run a function at every pageload (before anything else) and check if anything needs to be moved to the archive. If anything needs to be taken care of, do it.

    If you do it this way, you know that the page the visitors are seeing always is updated. If you use some sort of cron_job or event like you talked about, some of those auctions might be “expired” a few seconds after the job is executed and is therefore displayed as incorrectly active for almost another minute.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search