[英]Running PHP script from cron
I am trying to run a PHP script through a cronjob
.我正在尝试通过
cronjob
运行 PHP 脚本。 I already did this hundred of times, but now it's not working and I cannot figure out why.我已经这样做了数百次,但现在它不起作用,我不知道为什么。
I created a script called update_db.php
in /var/www/html/
When I run the script by hand:当我手动运行脚本时,我在
/var/www/html/
创建了一个名为update_db.php
的脚本:
php /var/www/html/update_db.php
everything works fine.一切正常。 When I put this into a
cronjob
, it does nothing.当我把它放入
cronjob
,它什么也不做。 My cronjob:我的定时任务:
* * * * * /usr/bin/php /var/www/html/update_db.php
I tried to put a bash script in front of it that calls the PHP script, but, again, it only works when calling by hand, not from a cron.我试图在它前面放置一个调用 PHP 脚本的 bash 脚本,但同样,它仅在手动调用时有效,而不能从 cron 调用。
There are no errors in the syslog.系统日志中没有错误。 Also no mail in
/var/mail
.在
/var/mail
也没有/var/mail
。 I restarted cron already, but no effect.我已经重新启动了 cron,但没有效果。
I use ubuntu 14.04.我使用 ubuntu 14.04。
Can anyone help me?谁能帮我?
Is * * * * * php /var/www/html/update_db.php
not working? * * * * * php /var/www/html/update_db.php
不工作吗? You shouldn't need to use /usr/bin/php
.您不需要使用
/usr/bin/php
。
Also, check to make sure crons are running on your current system and that your files/directories have the appropriate permissions to be run by the cron.此外,检查以确保 cron 正在您当前的系统上运行,并且您的文件/目录具有由 cron 运行的适当权限。
CRON "should" be logging. CRON“应该”记录。 Check the /var/log/cron, looking for your script errorrs or otherwise.
检查 /var/log/cron,寻找您的脚本错误或其他。
some implementations of cron need a full on restart - I have personanlly never had this issue, but I know fellow admins who have spent far too much time chasing fault, when a simple restart did the trick. cron 的某些实现需要完全重启 - 我个人从来没有遇到过这个问题,但我知道其他管理员花了太多时间来追查错误,而简单的重启就解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.