简体   繁体   English

这两个Cron工作之间有什么区别?

[英]What is difference between these two cron jobs?

I am very new to php, if anyone can help me by telling what the difference is between these two cron commands, I would be very thankful: 我对php很陌生,如果有人能通过告诉我这两个cron命令之间有什么区别来帮助我,我将非常感激:

/usr/local/bin/php -q /home/delightl/public_html/myfolder/run.php

and

php -q /home/delightl/public_html/myfolder/run.php

I am totally confused.. On my GoDaddy server, the second command worked, but in another resellerclub server both worked. 我完全感到困惑。在我的GoDaddy服务器上,第二个命令起作用了,但是在另一个resellerclub服务器上,两个命令都起作用了。 What is difference between these commands? 这些命令之间有什么区别?

The only difference is that one specifies the full path to the PHP binary, and the other doesn't. 唯一的区别是,一个指定了PHP二进制文件的完整路径,而另一个则没有。

PHP can be installed in different locations. PHP可以安装在不同的位置。 That's why it works on one server, and not the other. 这就是为什么它可以在一台服务器上运行,而不能在另一台服务器上运行的原因。

There is a pro and a con to using either of these: 使用以下两种方法都有利有弊:

/usr/local/bin/php -q /home/delightl/public_html/myfolder/run.php

Pro: Specifies the full path to the PHP binary, does not depend on the user's $PATH environment variable to correctly include the path to where PHP is installed. 专业版:指定PHP二进制文件的完整路径,而不依赖于用户的$PATH环境变量来正确包含PHP的安装路径。
Con: The location of the PHP binary can vary from system to system. 缺点: PHP二进制文件的位置因系统而异。

php -q /home/delightl/public_html/myfolder/run.php

Pro: Usually does not require alteration from system to system. 优点: 通常不需要在系统之间进行更改。
Con: Will frequently not work as many PHP packages will not add PHP to the $PATH of the cron user, or the environment in which cron is run is left blank or not populated because it is not an interactive session. 缺点:由于许多PHP软件包不会将PHP添加到cron用户的$PATH ,因此常常无法正常工作,或者运行cron的环境空白或未填充,因为它不是交互式会话。

IMHO the best solution is to always use the full path. 恕我直言,最好的解决方案是始终使用完整路径。 If you are not certain what the path is run which php via shell which will tell you the full path to the binary, so long as it is in your $PATH . 如果你不能确定什么样的路径运行which php通过shell它会告诉你的完整路径的二进制,所以只要是在你的 $PATH

See: http://en.wikipedia.org/wiki/PATH_%28variable%29 请参阅: http : //en.wikipedia.org/wiki/PATH_%28variable%29

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

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