简体   繁体   English

Cron作业PHP脚本无法运行

[英]Cron job PHP-script won't run

Thanks for looking at this post. 感谢您看这篇文章。 My problem is that I can't make cron to run php script. 我的问题是我不能让cron运行php脚本。 I don't want this job to look like 我不希望这份工作看起来像

* * * * * lynx -dump http://www.somedomain.com/cron.php
or * * * * * wget http://www.somedomain.com/cron.php,

because this way, as I understand it will be run as apache user. 因为这样,据我了解,它将以apache用户身份运行。 Rather I would like this file to have permissions 750(invisible for outside) and have it run as a user user_name. 而是我希望此文件具有权限750(外部不可见)并以用户user_name的身份运行。 So, I tried to put settings in /etc/crontab: 因此,我尝试将设置放在/ etc / crontab中:

*/1 * * * * php /var/www/site1/json_renew.php >/dev/null
or */1 * * * * /usr/bin/php /var/www/site1/json_renew.php
or */1 * * * * user_name php /var/www/site1/json_renew.php
or same from $crontab -e. 

But the script just won't run, although it runs perfectly, when run from command line: 但是,从命令行运行时,尽管脚本可以完美运行,但它不会运行:

$ php /var/www/site1/json_renew.php

Thanks! 谢谢!

I had a similar issue, the script ran fine when the URL was visited directly, and would run sometimes, seemingly randomly. 我有一个类似的问题,当直接访问URL时脚本运行良好,并且有时会随机运行。 Turns out it was host server resource issue. 原来是主机服务器资源问题。 Hostgator wont run a cron job when I'm connected via SSH with Putty on 2 computers. 当我在两台计算机上通过SSH与Putty连接时,Hostgator不会执行cron作业。

From their help pages "SSH access is limited to two simultaneous connections on Shared and Reseller plans. Note: Any cron jobs configured will require one of these sessions to be available in order to run, since cron jobs run under the same shell as SSH." 在他们的帮助页面上,“ SSH访问仅限于Shared和Reseller计划上的两个同时连接。注意:配置的任何cron作业都需要这些会话之一才能运行,因为cron作业与SSH在同一Shell下运行。 ”

When I close the SSH connection, the cron job immediately runs. 当我关闭SSH连接时,cron作业立即运行。

Maybe your host has a similar rule? 也许您的房东有类似的规定?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM