I was wondering if it is somehow possible to do this; it is more to do with MySQL, but I figured that most of the php geniuses would know how to use MySQL also.
Lets say I have a table that contains both the fields number and maxNumber.
I want to make it that number increments by one every 5 minutes until it reaches maxNumber, where it will not increment any more until some of the field number has been used. Is this possible?
If you're on linux you can create a cron job for this. You can tell the script to run every 5 minutes and do exactly what you need. You can also create a constant running php script that will check every 5 minutes by using a counter and overriding the max execution time within the script... but that is a very inefficient method, use a cron job if you can.
Depending on what it is you're actually trying to do, it may be that you could add a "start time" field to the DB table, then do a little math in your query and/or PHP code to determine how many minutes it's been since that time and add the appropriate amount to the value, making sure it's no more than the max.
I was fearing I would have to do that, but I guess it seems like the best idea NogDog. Thanks for the advice Jarrod1937, however I looked up cron jobs online and there was nothing that made any sense - all of this linux and unix business. I have windows so... not really feasible (I think).
I am so lazy, I was looking for a quick way out, but I guess I'll have to do it the long way.
Task scheduling is the windows equivalent. Nogdog's suggestion will work, but its assuming you have someone to execute that query statement... i was basing my suggestion on your requiring of an automatic executing script.
Last edited by Jarrod1937; 03-07-2010 at 12:13 PM.
I think it comes down to what this timing/incrementing is actually used for. If it's just to display a different value when a user views a page, based on how long it's been since some start time, then I would go with my suggestion, as it would only do the processing when actually needed (maybe using some caching if you're expecting a lot of traffic). If, on the other hand, you need to actually change some value in the database as the clock keeps ticking, then I'd probably look into using a scheduler/cron task as Jarrod suggested.
Ok, so my Webserver is Linux apparently, what language do I have to learn to do Cron Tasks. I barely know php, I've been learning it very on/off and spend barely any time on it.
Are cron tasks complicated?
As nogdog said, it depends on your needs, but if you think you need a cron job, all you need to do is write your script in php, and tell the cron daemon to run it.
Originally Posted by esquilado
If you have cpanel, login to it and go to cron jobs and click basic, you then point it to the absolute path of your script on your server, set the execution time/interval and save it.
If you don't have cpanel, you'll need to connect to the server by command line (ssh) and follow these instructions:
note: be careful to make sure you set the time interval right, you can easily cripple your server if you run complex scripts too often ;-)
Last edited by Jarrod1937; 03-07-2010 at 02:06 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)