Updating database on 12am

Discussion in 'Web Design and Development' started by pdent1, Feb 4, 2009.

  1. pdent1 macrumors newbie

    Joined:
    Feb 3, 2009
    #1
    I store stats for my members and would like them automatically reset them all at 12am...How would I go about doing this? Just give an example if you know how to do this and I should be able to go from there.
     
  2. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
  3. Angelo95210 macrumors 6502a

    Angelo95210

    Joined:
    Jan 7, 2009
    Location:
    Paris, France
    #3
    Yeah a cron job sounds great... set up a php file with the queries to execute in mysql. Than add this file to the cron job (check the syntax).

    Beware some hosting companies do not allow to set up cron jobs... You then know what to do... I have heard about third parties cron jobs as well, but I dont really trust them...

    Last alternative, you can set up the execution of this job in an often used php file (if your site as traffic) and as soon as a parameter is valid it will execute the job.

    ex
    if date<>date last query => do a new query....

    Not sure it s well explained but it s a draft...
     
  4. pdent1 thread starter macrumors newbie

    Joined:
    Feb 3, 2009
    #4
    chico and angelo thanks I have never set up a cron job so I wasn't to sure thanks I'll look into it and see how it works. If not I'll do the if date idea...Thanks again Just signed in to cpanel and read cron jobs I can use this to make my chat which is through database to stay at a certain place every hour :) so I just solved 2 problems with 1 answer
     
  5. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #6
    In addition to the helpful links supplied by Angelo95210, I have direct experience running PHP scripts via cron on our Linux server.

    All of the following is via CLI (command line interface, i.e. a shell):

    Step 1: Write your PHP script and make sure it can run without errors via CLI using full paths, i.e. if you typed in manually:

    Code:
    $> /path/to/php /path/to/yourscript.php
    Note: If you're not sure of the path to PHP, type in "which php"

    Step 2: To EDIT the crontab type in "crontab -e"

    To run this at 12:00am add the following:

    Code:
    # Yourscript.php runs 12:00 every day (this is a comment)
    0 0 * * 0 /path/to/php /path/to/yourscript.php
    Two optional commands to add into crontab are:

    1) Time zone i.e. "TZ=EST5EDT" - use whatever is local to you (see possible time zones in /usr/share/zoneinfo/ on most *nix systems)
    2) E-Mail all crontab output to you, i.e. "MAILTO="yourname@yourdomain.com"

    Step 3: Save and exit the editor

    To LIST the crontab to ensure it was updated properly, type in "crontab -l"

    Obviously, use your real paths - the above example code is for syntax demonstration purposes.

    -jim
     
  6. Angelo95210 macrumors 6502a

    Angelo95210

    Joined:
    Jan 7, 2009
    Location:
    Paris, France

Share This Page