www.webdeveloper.com
Results 1 to 8 of 8

Thread: Automatic execution

  1. #1
    Join Date
    Nov 2009
    Posts
    61

    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!

  2. #2
    Join Date
    Mar 2010
    Posts
    672
    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Nov 2009
    Posts
    61
    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.

  5. #5
    Join Date
    Mar 2010
    Posts
    672
    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 11:13 AM.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Nov 2009
    Posts
    61
    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?

  8. #8
    Join Date
    Mar 2010
    Posts
    672
    Quote Originally Posted by esquilado View Post
    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.
    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-...-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 ;-)
    Last edited by Jarrod1937; 03-07-2010 at 01:06 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles