I'm using PHP and was wondering how can i run my PHP script to run at midnight and check if a member has been inactive for six months if so delete.
-
The title says cron. So I assume he's talking about *nix.Nithesh Chandra– Nithesh Chandra2010-10-18 14:30:59 +00:00Commented Oct 18, 2010 at 14:30
-
I plan on using Linux and Windows as well.HELP– HELP2010-10-18 14:32:00 +00:00Commented Oct 18, 2010 at 14:32
-
the -1 is uncalled for haterz u know who u areHELP– HELP2010-10-18 14:33:32 +00:00Commented Oct 18, 2010 at 14:33
-
possible duplicate of add php script in cron for scheduled task from php?Gordon– Gordon2010-10-18 14:40:11 +00:00Commented Oct 18, 2010 at 14:40
-
Author terminology did not explicitly suggest *nix. I concur, -1 is a bit harsh.Ben Everard– Ben Everard2010-10-18 14:40:11 +00:00Commented Oct 18, 2010 at 14:40
2 Answers
See Crontab: http://en.wikipedia.org/wiki/Cron
example crontab entry for 12:01 am:
1 0 * * * /usr/bin/php /home/whatever/myscript.php > /home/whatever/outlog.txt
command to edit the crontab entries for the logged in user:
crontab -e
Comments
A cron line like the following should suffice:
0 0 * * * /usr/bin/php /path/to/script
I would advise that you run the script at an irregular time (i.e not on an hour or day boundary), as you may get to the situation when you have too many scheduled tasks occurring at the same time.
If the script generates any output, then that will typically be emailed to the user mailbox. So, you should design your script to not generate output in the normal case. Or, alternatively redirect the output to a file or the syslog.
I use syslog redirection quite a lot. For example the following will log the commands output into the syslog using the tag my_script.
20 1 * * * /usr/bin/php /path/to/script | /usr/bin/logger -t my_script