[英]PHP Fatal error: require_once(): Failed opening required
I'm just trying to create a file to be run from a cron job but however I'm getting the below error log. 我只是想创建一个要从cron作业运行的文件,但是我得到了以下错误日志。
PHP Warning: require(../app/src/app.class.php): failed to open stream: No such file or directory in /var/www/mosto.in/manual/gateway.php on line 4 PHP Fatal error: require(): Failed opening required '../app/src/app.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/mydomain.in/manual/gateway.php on line 4
My gateway.php file 我的gateway.php文件
set_time_limit(0); require('../app/src/app.class.php');
I'm confused if I'm running the same file on my ssh server using the below path the file not generating any errors & working very fine. 如果我在ssh服务器上使用以下路径运行相同的文件,我会感到困惑,该文件不会产生任何错误并且工作得很好。
*cd /var/www/mosto.in/manual/ *php gateway.php
Crontab crontab的
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /usr/bin/php /var/www/mosto.in/manual/gateway.php > /var/log/gateway.log 2>&1
Please help me. 请帮我。
Thanks in advance. 提前致谢。
Your problem is most likely that the working directory for the cron daemon is not the same as when you execute it manually. 您的问题很可能是cron守护程序的工作目录与手动执行时的工作目录不同。 See if this works: 查看是否可行:
* * * * * cd /var/www/mosto.in/manual/ && /usr/bin/php gateway.php > /var/log/gateway.log 2>&1
If it does, I'd consider moving the cd
and php
call into a script file and calling that from your crontab instead - but that might just be me :p 如果是这样,我会考虑将cd
和php
调用移到脚本文件中,然后从您的crontab中调用它-但这可能只是我:p
When you execute a script through shell / crontab, the best way to call required files are to give absolute paths in the require() or require_once() statements. 通过shell / crontab执行脚本时,调用所需文件的最佳方法是在require()或require_once()语句中提供绝对路径。
require('/var/www/mosto.in/app/src/app.class.php');
Hope this will work for you. 希望这对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.