使用CLI的子目录的set_include_path()?

时间:2012-06-19 14:47:22

标签: php zend-framework command-line-interface autoload include-path

我在应用程序中使用Zend Framework 1.11。我正在尝试实现performance upgrade suggested by the manual以消除不必要的require_once()语句并进行完全自动加载。这在正常的应用程序中工作正常。

我还有一个CLI接口,我为守护进程编码(通过Bootstrap.php中的自定义路由器),它似乎不想对我的更改很好。它与我设置的包含路径有关,该路径当前在我的index.php ZF入口点中配置:

set_include_path(implode(PATH_SEPARATOR, array(
   realpath(APPLICATION_PATH . '/../library/'),
   get_include_path(),
)));

库文件夹的布局如下:

- library
   -Zend
      -Acl
      -Amf
       ... etc, Zend Framework files
   -Custom
      -Api
      -Twitter
       ... etc, My Custom library files

通过CLI运行应用程序时,它无法在这些目录或子目录中找到任何文件。所以我将包含路径更改为:

set_include_path(implode(PATH_SEPARATOR, array(
   realpath(APPLICATION_PATH . '/../library/'),
   realpath(APPLICATION_PATH . '/../library/Custom/Twitter/'),
   get_include_path(),
)));

然后它能够​​找到我需要的文件。

TL; DR; 我在这些库中有很多文件,如果我必须手动将每个文件夹放入包含路径,我可能从自动加载中获得的任何性能提升都会消失。还有更好的方法吗?

P.S。一时兴起,我也尝试了像 /../ library / * 这样的路径,但这也不起作用。

0 个答案:

没有答案