Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- How to create a PHP cron job


swa66 - 5:52 pm on Aug 9, 2012 (gmt 0)


The OP's path to php was /usr/bin/php, should not be needed to export anything.

The output of the command in cron is sent to the user who's crontab it is -> check if your local mail works and read it ...

What I've dealt with as a sysadmin years ago was a youngster reading the man pages and getting confused.
I'm wondering if that's not the case here.

What are you doing to add a line to cron ?
crontab -e ?

How do you check what's in your crontab ?
crontab -l ?
[let's hope you know how to use vi]

In the contab you add a line like
30 18 * * * /usr/bin/php /root/command.php

There is no need to add #!/bin/sh or anything like that. (luckily it's a comment in crontabs so you're safe)

The php command as said before needs to start with <?php and end with ?> and should work if invoked from the command line.

If you have trouble getting to know if it runs:
0 * * * * echo "works"
should send you an email once an hour, on the hour. It's sent locally to your account name - so unless you have it configured to send it elsewhere it'll arrive locally.


On thing: I don't use Linux, so its interface to set what cron does might be a bit off from the bsd unix way of doing things.


Thread source:: http://www.webmasterworld.com/php/4482541.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com