【问题标题】:trying to run a cronjob with file included but when i run command line it continue saying there's an error and the files arent there尝试运行包含文件的 cronjob,但是当我运行命令行时,它继续说有错误并且文件不存在
【发布时间】:2013-01-02 20:42:15
【问题描述】:

好吧,我正在尝试运行一个包含一些文件的 cronjob,但是当我通过命令行运行它时,它一直说文件不存在

这里是php文件:

include "../includes/common.php";
require_once('../anotherfile.php');
require_once '../swift/lib/swift_required.php';

//some database things

这是我运行的命令行:

/usr/local/bin/php /home/xxxxx/public_html/cron/somefile.php

这是我得到的错误:

Warning: include(..includes/common.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/cron/somefilek.php on line 3
Warning: include(..includes/common.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/cron/somefilek.php on line 3
Warning: include(): Failed opening '..includes/common.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxx/public_html/cron/somefilek.php on line 3
Warning: require_once(..anotherfile.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/cron/somefilek.php on line 4
Fatal error: require_once(): Failed opening required '..anotherfile.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxx/public_html/cron/somefilek.php on line 4

由于某种原因,它没有说明 swift_required.php

【问题讨论】:

  • 你确定你没有打错字吗?你的错误说:include(..includes/common.php) 而不是include(../includes/common.php)
  • 是否有嵌套包含?像 common.php 有一个不起作用的包含...我想我可能读错了错误。
  • john 我已经尝试了两种方法都没有工作 ../ 只是 .. common.php 适用于整个网站,并且有一些包含但它们工作正常
  • 它没有提及swift_required.php 的原因是因为您之前有anotherfile.php required 不包括在内。由于它不能包含anotherfile.php 和您require,因此程序会因错误而终止。正如它所说的Fatal error
  • 是的,我明白了,谢谢

标签: php shell cron


【解决方案1】:

您需要先在您的目录中“定位”或在您的包含中使用绝对路径。尝试将您的命令更改为:

cd /home/xxxxx/public_html/cron && /usr/local/bin/php /home/xxxxx/public_html/cron/somefile.php

【讨论】:

  • 太奇怪了……你确定文件的路径是正确的并且你有权限读取它吗?
  • 关于premission的路径现在是正确的,我现在必须检查一下
  • 所以正确的文件路径是:/home/xxxxx/public_html/includes/common.php
  • 当你通过命令行运行时,你确定权限是正确的吗?apache不是访问文件的用户。
  • 前提是正确的,但是我认为我已经创建了一个测试文件并将其放在同一个文件夹中的 cron.. 从那里做include( 'tesfile.php'); 的路径我当时做得很好将文件从 domain/con/.. 带到 domain/.. 并将其包含为:include( '..tesfile.php); 但是这不起作用。这让我认为这是一个路径问题..你如何返回一个目录?
猜你喜欢
  • 2014-01-17
  • 2021-02-15
  • 1970-01-01
  • 2014-11-11
  • 2013-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多