im trying to set up a cronjob to run a PHP file. i just want to know if i am doing it right or not.
lets say the php is located at http://mysite.c开发者_StackOverflow中文版om/myscript/cronjob.php, and i want it to run every 3 hours.
i am very new to cronjobs so i apologise if it seems like i have no clue what i am doing.
Minute Hour Day Month Weekday Command
* */3 * * * http://mysite.com/myscript/cronjob.php
i want this to run that PHP script every 3 hours. will this work or do i have to use a different command?
No, this won't work. A URL is not an executable, it is simply a URL.
You could put wget http://mysite.com/myscript/cronjob.php
for your command, but is that really what you want?
The best way (if the script is on the local server) is to call PHP directly:
php /var/www/myscript/cronjob.php
Almost, this should do it
* */3 * * * wget -q -o /dev/null http://mysite.com/myscript/cronjob.php
or with curl
* */3 * * * curl -s -o /dev/null http://mysite.com/myscript/cronjob.php
the -s / -q will silent the output and the -o will redirect the scripts output into /dev/null
In addition to what others have said about not being able to specify a URL to query:
I've found several references online that warn
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
However assuming repeat patterns are supported, it should work.
So a more portable way would be to do:
* 0,3,9,12,15,18,21 * * * php /var/www/myscript/cronjob.php
精彩评论