tags:

views:

57

answers:

2

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.

+5  A: 

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
Fosco
A: 

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
ar