运行PHP文件时出现Cron作业错误

use*_*331 1 php cron crontab

我试图通过cron作业运行一个php文件,当我手动运行它时文件工作正常,但是当我在cron作业中运行它时,我收到此错误:

Warning: include(classes/EmailAddressValidator.php): failed to open stream: No such file or directory in /var/www/onecent_dev/classes/MiscFunctions.php on line 3

Warning: include(): Failed opening 'classes/EmailAddressValidator.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/onecent_dev/classes/MiscFunctions.php on line 3
Run Code Online (Sandbox Code Playgroud)

MiscFunctions.php和EmailAddressValidator.php都是现有文件并且位于正确的位置,是什么给出的?

谢谢

Ale*_*sky 10

看起来你的include_path正在解决.无论cron碰巧将当前目录设置为,而不是脚本所在的目录.尝试首先将crontab编辑为cd:

0 * * * * cd /path/to/script && php script.php
Run Code Online (Sandbox Code Playgroud)

或者明确提供include_path:

0 * * * * php -d include_path=/path/to/script script.php
Run Code Online (Sandbox Code Playgroud)