【问题标题】:Cron Job Error when running a PHP file运行 PHP 文件时的 Cron 作业错误
【发布时间】:2012-04-28 23:32:50
【问题描述】:

我正在尝试通过 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 都是现有文件并且在正确的位置,有什么用?

谢谢

【问题讨论】:

    标签: php cron crontab


    【解决方案1】:

    看到这个问题:PHP: Require path does not work for cron job?

    您的 include_path 不包含您正在执行的脚本的路径。

    【讨论】:

      【解决方案2】:

      看起来您的 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
      

      【讨论】:

      • 使用include_path 方法对我不起作用。我得到“无法打开输入文件:script.php”第一个选项有效并且看起来很简单。我的问题是,在 Cron 工作中 cding 有什么缺点吗? Cron 有自己的 shell 并在那里做任何事情,对吧?这是否意味着未来的工作在技术上将在 /path/to/script 中运行?那么 Cron 的默认工作目录在哪里呢?谢谢
      • “这是否意味着未来的工作在技术上会在 /path/to/script 中运行?” 不,只是这个工作。你也可以在没有 cd 的情况下做php /path/to/script.php
      猜你喜欢
      • 2017-09-05
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 2010-09-12
      相关资源
      最近更新 更多