简体   繁体   English

Crontab和PHP脚本

[英]Crontab and PHP script

I'm currently experiencing an issue that I just can't find it being solved online. 我目前遇到的问题是我无法在线解决该问题。 I have tried two different Operating systems, and both have the same difficulty. 我尝试了两种不同的操作系统,并且都具有相同的难度。 One is Ubuntu, the other os OSx. 一个是Ubuntu,另一个是OS OSx。

now the issue is, for this example, running a cron every minute to hit a .php file which in turn increments the count of a value found in a .txt file by 1. 现在,对于此示例来说,问题是每分钟运行一次cron来命中.php文件,这反过来会使.txt文件中找到的值的计数增加1。

At the beginning of the .php file I have: 在.php文件的开头,我有:

#!/usr/bin/php #!/ usr / bin / php

I have also tried adding the quiet tag at the end. 我还尝试在末尾添加安静标签。 Which didn't result in the cron working. 但这并未导致cron工作。

The cron command is as follows: cron命令如下:

          • php /var/www/cron/index.php >/dev/null 2>&1 php /var/www/cron/index.php> / dev / null 2>&1

The output found inthe syslog under CRON is: 在CRON下的syslog中找到的输出为:

(user) CMD (php /var/www/cron/index.php >/dev/null 2>&1) (用户)CMD(php /var/www/cron/index.php> / dev / null 2>&1)

With no errors. 没有错误。 If I run that command as it is given. 如果我按照给出的命令运行。 The count in the .txt is incremented by 1. But there is nothing to show why the cron doesn't allow this to happen. .txt中的计数增加1。但是,没有任何内容可以说明为什么cron不允许这种情况发生。

Sorry for the essay. 对不起这篇文章。 Any suggestions would be greatly appreciated. 任何建议将不胜感激。

Just to leave an answer on this for future reference for others. 只是留下一个答案,以供将来他人参考。 Please check the files included into the php file being run by the Cron have absolute paths and not just paths local to the file itself. 请检查Cron正在运行的php文件中包含的文件是否具有绝对路径,而不仅仅是文件本身的本地路径。

Ie: do NOT have: include 'inc/test.php'; 即:没有:包括“ inc / test.php”;

You would need to use for example: include '/var/www/cron/inc/test.php'; 您将需要使用例如:include'/var/www/cron/inc/test.php';

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

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