Hi, my site has allows users to sign up and buy e-learning courses. As soon as they purchase a course, they have 1 week (7 days) to START the course so the following is set as soon as the purchase has been made: - $course_status is set to 'purchased' - $start_timestamp is set (set to one week from the current time of the purchase) I am running a cron job to check for courses that have not been started within the week (7 days) timeframe: check all missions where $course_status = 'purchased' IF $current_timestamp > $start_timestamp SET $course_status to 'not_started' ELSE do nothing My question is, how many times should i be running this cron a - run the cron 48 times a day (checking for courses that have not been started every 30 minutes throughout the day) (is this bad practice, would i be running the cron too often, with a possibility of slowing the site down) b - should i add a $purchase_hour to the database and then run the cron every hour but only query courses where $purchase_hour = $current_hour (the hour at the time the cron is run) Thanks in advance for your help on this
How important is the actual time? Would it be better to simply store the date instead of a timestamp and then check based off of that? You would have less room for error and could run the cron once a day then. As far as bad practice on the first one, depending on the time sensitiveness there is nothing wrong with it - I've run a cron every 15 minutes a day due to the requirements of the project - just make sure that you never have a race condition where one cron starts before the previous one ends. Will it slow things down? That depends on how much work the cron job has to do. If you are performing updates like that frequently, you should make sure your database is using the InnoDB engine and not MyISAM - MyISAM will lock the whole database during updates while InnoDB does row level locking. While it might not make a big deal on a couple thousand of records since the updates are quick, you will notice it over time when your table grows to larger size and it will be harder to convert it at that point in time.