【问题标题】:php script require() statement fetches file when running from browser but not when running from Plesk CRON jobphp 脚本 require() 语句在从浏览器运行时获取文件,但在从 Plesk CRON 作业运行时不获取文件
【发布时间】:2019-07-04 03:42:05
【问题描述】:

如果我通过从浏览器访问 php 文件来运行它,我的任务脚本可以正常工作。但是,当我尝试通过 Plesk 任务计划程序运行它时,它会因为无法加载 require() 文件的致命错误而失败。

require语句是一个简单的相对路径:

require('../../../app.config.php');

错误是:

PHP Fatal error: require(): Failed opening required '../../../app.config.php'

我认为这可能与include_path 有关,但我对此了解不多,所以对那个有点迷茫。

任何帮助都会很棒!

【问题讨论】:

    标签: php linux cron scheduled-tasks plesk


    【解决方案1】:

    当前目录解析的相对路径。解决方案:获取脚本目录并结合相对路径,类似:

     require(dirname(__FILE__).'/../../../app.config.php');
    

    【讨论】:

      【解决方案2】:

      您需要使用绝对路径。如果直接调用脚本或者脚本包含在另一个脚本中,可能会产生不同的相对路径。

      例如:

      a.php is on path A/B/C the ../../ will result in in A/
      b.php is on path A/B/C/D, if it inlcudes the a.php then the ../../ on a.php will result in A/B/.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-19
        • 2011-11-29
        • 2015-03-22
        • 2010-09-14
        • 2018-01-15
        • 2019-06-22
        • 1970-01-01
        • 2016-04-29
        相关资源
        最近更新 更多