Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pdent1

macrumors newbie
Original poster
Feb 3, 2009
4
0
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.
 
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...
 
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
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.