What should be given as the url to the script while adding it to cron scheduler.
The script is at domain.com/scripts/script.php
PS:I am using cPanel
4 Answers
Here's a copy / paste out of one of the cron jobs that I run:
00 7 * * 1,2,3,4,5 /usr/local/bin/php /home/processing/process.php
You must use the absolute path to the PHP binary as well as the absolute path to the script itself.
none of these. but full absolute path from the root of the filesystem. you can see that path with this code
echo __FILE__;
8 Comments
/home/..., which is the same as output by echo __FILE__; . And there is no error in the script - I'm now using a 2 line script to test. I was wondering if I've to do anything more while adding a cron job. Currently I've added the job to run every minute (for testing ofcourse), and the command as /home/user/php /home/user/public_html/scripts/script.php. I added the url to php binary now, but it is not working now, and did not without it.log_errors and error_log directives in the php file or use piping, redirecting script output to some file. Make sure that all filenames used by this script also have full absolute pathslog_errors and error_log. And like I said the script is just some lines now, so if it's run there should be an output. But my assumption is that it ain't run by cron. So I think there could be a problem in the way I added the job (I did it by using cPanel's interface and not thru command). Here's what it looks like: 0 * * * * /home/domainname/php /home/domainname/public_html/scripts/script.phpI had the habit of changing directory cd /var/www/vhosts/somesite.com/httdocs before running script with /usr/bin/php -f ./scriptname.php 2>&1 all in the same line on crontab.
I redirect the error output to get notified by email in case an execution error occured.
From crontab :
[email protected]
* * * * * cd /var/www/vhosts/domain.com/httpdocs/; /usr/bin/php -f testmail.php 2>&1