0

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.

6
  • The title says cron. So I assume he's talking about *nix. Commented Oct 18, 2010 at 14:30
  • I plan on using Linux and Windows as well. Commented Oct 18, 2010 at 14:32
  • the -1 is uncalled for haterz u know who u are Commented Oct 18, 2010 at 14:33
  • possible duplicate of add php script in cron for scheduled task from php? Commented Oct 18, 2010 at 14:40
  • Author terminology did not explicitly suggest *nix. I concur, -1 is a bit harsh. Commented Oct 18, 2010 at 14:40

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.