我正在尝试通过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
MiscFunctions.php 和 EmailAddressValidator.php 都是现有文件,并且位于正确的位置,什么?
谢谢
看起来您的include_path正在解析 . 到任何 cron 碰巧将当前目录设置为什么,而不是脚本所在的目录。尝试先将 crontab 编辑为 cd:
0 * * * * cd /path/to/script && php script.php
或者明确提供include_path:
0 * * * * php -d include_path=/path/to/script script.php
看到这个问题: PHP:需要路径对 cron 作业不起作用?
include_path不包含正在执行的脚本的路径。