I have the following commands set in my crontab
0 * * * * root cd /home/domain/public_html/webcrawler && php cron1.php
40 * * * * root cd /home/domain/public_html/webcrawler && php cron2.php
The thing is they are not running. Is there any noticeable errors in the commands I have set? The php scripts run fine when run from ssh, or loaded in the browser. I have tried with and without root at the start.
您应该使用完整路径调用PHP cron作业(请注意,您的PHP可能位于其他位置)
0 * * * * /usr/bin/php /path/to/your/script.php
Change out the &&
with ;
to read like
0 * * * * root cd /home/domain/public_html/webcrawler; php cron1.php
or execute it from the absolute path
0 * * * * root php /home/domain/public_html/webcrawler/cron1.php
When using the absolute path you can force your cron script's current working directory by performing
chdir(__DIR__); //or chdir(dirname(__FILE__));
You can also add the PHP shebang to the top of you cron.php file (your php binary may have a different path)
#!/usr/bin/php
http://php.net/manual/en/features.commandline.usage.php
Then you can execute the script without needing to reference the php binary location using
0 * * * * root /home/domain/public_html/webcrawler/cron1.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.