Jump to content

Execute certain code at a specific relative time...


elad135

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.