elad135 Posted April 14, 2011 Share Posted April 14, 2011 I'm kind of a beginner in PHP and I'm not sure how complicated is this thing I need to do so I just need a little bit of help. Anyway, I have this clock counter on a few of my pages, counting down to 0 and what I need to do is execute certain code 15 minutes before a counter reaches 0. It's basically the same code but it needs to run every time one of the counters is 15 minutes away from 0. Any simple way for me to achieve this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/233748-execute-certain-code-at-a-specific-relative-time/ Share on other sites More sharing options...
Stooney Posted April 14, 2011 Share Posted April 14, 2011 read up on cron jobs Quote Link to comment https://forums.phpfreaks.com/topic/233748-execute-certain-code-at-a-specific-relative-time/#findComment-1201739 Share on other sites More sharing options...
nethnet Posted April 14, 2011 Share Posted April 14, 2011 Cron jobs could accomplish this if it needs to be executed precisely 15 minutes before the counter reaches 0. Although, if you just need to give the illusion that it is being executed 15 minutes prior, cron jobs would be an unnecessary complication. I worked on a project once where every player of the game was meant to be given a certain amount of resources every 30 minutes. Instead of using a cron job that ran exactly every 30 minutes, I just faked it by running a check every time a player loaded their account. It would check to see how long it has been since they last checked it, and give an appropriate amount of resources depending on the time. So if 2 hours had passed, it would give, at that moment, 4 times the amount of resources that players were meant to get every 30 minutes. This way, you give the illusion that it is being updated every 30 minutes, without actually having a cron job running. This is a very common practice in situations like this. Obviously, if it was absolutely necessary to do it spot on time, then this method wouldn't work for you. Quote Link to comment https://forums.phpfreaks.com/topic/233748-execute-certain-code-at-a-specific-relative-time/#findComment-1201742 Share on other sites More sharing options...
elad135 Posted April 15, 2011 Author Share Posted April 15, 2011 Thanks guys - specially nethnet. Your idea about creating the illusion of the stuff I need to happen actually would work quite well in this particular case. Quote Link to comment https://forums.phpfreaks.com/topic/233748-execute-certain-code-at-a-specific-relative-time/#findComment-1201931 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.