我使用 Zend Framework 编写了一个命令行实用程序来执行一些夜间报告。它使用了大量与随附站点相同的功能。当我手动运行它时效果很好,但是当我在 cron 上运行它时,我遇到了包含路径问题。似乎它应该很容易用 set_include_path 修复,但也许我错过了什么?
我的目录结构如下所示:
/var/www/clientname/
application
Globals.php
commandline
commandline_bootstrap.php
public_html
public_bootstrap.php
library
Zend
在 public_bootstrap.php 我使用 set_include_path 没有问题,相对于当前目录:
set_include_path('../library' . PATH_SEPARATOR . get_include_path());
如果我理解正确,我需要在 commandline_bootstrap.php 中输入绝对路径,以便 cron 知道所有内容在哪里。我的文件开始是这样的:
error_reporting(E_ALL);
set_include_path('/var/www/clientname/library' . PATH_SEPARATOR . get_include_path());
require_once "../application/Globals.php";
但是当我通过 cron 运行它时,出现以下错误:
PHP 致命错误:require_once(): 无法在 /var/www/clientname/commandline/zfcli.php 中打开所需的 '../application/Globals.php' (include_path='/var/www/clientname/library/')第 11 行
我认为 PHP 正在接受我的新路径,因为当我在命令行运行它并转储 phpinfo 时,我可以看到:
include_path => /var/www/clientname/library/:.:/usr/share/pear:/usr/share/php => .:/usr/share/pear:/usr/share/php
我承认这里的语法看起来有点奇怪,但我不知道如何解决它。任何建议将不胜感激。
谢谢夏天