/    Sign up×
Community /Pin to ProfileBookmark

Automatic execution

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?

Thanks guys!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@Jarrod1937Mar 07.2010 — 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.
Copy linkTweet thisAlerts:
@NogDogMar 07.2010 — 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.
Copy linkTweet thisAlerts:
@esquiladoauthorMar 07.2010 — 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.
Copy linkTweet thisAlerts:
@Jarrod1937Mar 07.2010 — 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.
Copy linkTweet thisAlerts:
@NogDogMar 07.2010 — 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.
Copy linkTweet thisAlerts:
@esquiladoauthorMar 07.2010 — 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?
Copy linkTweet thisAlerts:
@Jarrod1937Mar 07.2010 — 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?[/QUOTE]

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.

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:

http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

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 ;-)
×

Success!

Help @esquilado spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...