无法加载 Zend/Loader.php。试图找出原因?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load Zend/Loader.php. Trying to work out why?
提问by Binarytales
I have inherited a client site which crashes every 3 or 4 days. It is built using the zend-framework with which I have no knowledge.
我继承了一个客户站点,该站点每 3 或 4 天崩溃一次。它是使用我不知道的 zend 框架构建的。
The following code:
以下代码:
<?php
// Make sure classes are in the include path.
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'classes');
// Use autoload so include or require statements are not needed.
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
// Run the application.
App_Main::run('production');
Is causing the following error:
导致以下错误:
[Tue Sep 02 12:58:45 2008] [error] [client 78.***.***.32] PHP Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in /srv/www/vhosts/example.co.uk/httpdocs/bootstrap.php on line 6 [Tue Sep 02 12:58:45 2008] [error] [client 78.***.***.32] PHP Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='.:.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/vhosts/example.co.uk/httpdocs/bootstrap.php on line 6
I don't even know where to begin trying to fix this. My level of knowledge of PHP is intermediate but like I said, I have no experience with Zend. Also, contacting the original developer is not an option.
我什至不知道从哪里开始尝试解决这个问题。我的 PHP 知识水平中等,但就像我说的,我没有使用 Zend 的经验。此外,联系原始开发人员也不是一种选择。
The interesting thing is that even though the code is run every time a page of the site is hit the error is only happening every now and then.
有趣的是,即使每次点击网站页面时都会运行代码,但错误只是偶尔发生。
I believe it must be something to do with the include_path but I am not sure.
我相信这一定与 include_path 有关,但我不确定。
回答by Robin Barnes
for a start I think your include path should maybe have a trailing slash. Here is an example of mine :
首先,我认为您的包含路径可能应该有一个斜杠。这是我的一个例子:
set_include_path('../library/ZendFramework-1.5.2/library/:../application/classes/:../application/classes/excpetions/:../application/forms/');
You bootstrap file will be included by another file (probably an index.php file). This means that if your include path is relative (as mine is) instead of absolute, then the path at which Loader.php is looked for changes if the file including bootstrap.php changes.
您的引导文件将包含在另一个文件中(可能是 index.php 文件)。这意味着如果你的包含路径是相对的(就像我的一样)而不是绝对的,那么如果包含 bootstrap.php 的文件发生变化,那么查找 Loader.php 的路径也会发生变化。
For example, I have two index.php files in my Zend app, one for the front end, and one for the admin area. These index files each need there own bootstrap.php with different relative paths in because they are included by different index files, which means they have to be relative to the original requested index file, not the bootstrap file they are defined within.
例如,我的 Zend 应用程序中有两个 index.php 文件,一个用于前端,另一个用于管理区域。这些索引文件每个都需要有自己的 bootstrap.php 和不同的相对路径,因为它们包含在不同的索引文件中,这意味着它们必须相对于原始请求的索引文件,而不是它们在.
This could explain why your problem is intermittent, there could be another file including the bootstrap somewhere that is only used occasionally. I'd search through all the sites files for 'bootstrap.php' and see all the places which are including / requiring this file.
这可以解释为什么您的问题是间歇性的,可能还有另一个文件,其中包含仅偶尔使用的引导程序。我会搜索“bootstrap.php”的所有站点文件,并查看包含/需要此文件的所有位置。
回答by Adam Wright
The fact that it only happens sporadically makes me think this is less of a programming issue, and more of a sysadmin issue - if it were a defect in the implementation, you'd expect it to fail consistently considering the error is "No such file or directory". Two guesses
它只是偶尔发生的事实让我认为这不是一个编程问题,而是一个系统管理员问题 - 如果它是实现中的一个缺陷,你会期望它始终失败,因为错误是“没有这样的文件或目录”。两种猜测
There are multiple front-end web servers, and one of them is mis-configured (missing the Zend Framework).
The PEAR include directory is network mounted, and occasionally vanishes for short periods of time.
有多个前端 Web 服务器,其中一个配置错误(缺少 Zend 框架)。
PEAR 包含目录是网络安装的,偶尔会在短时间内消失。
It could be a more insidious file system problem, but one would think this would effect more than just one file.
这可能是一个更隐蔽的文件系统问题,但人们会认为这不仅会影响一个文件。
回答by Adam Wright
I had the same problem, but problem was in permissons to files. I gave chmod for all RWX and now is everything fine.
我有同样的问题,但问题在于文件的权限。我为所有 RWX 提供了 chmod,现在一切正常。
So maybe someone else will have same problem as me, then this was solution.
所以也许其他人会和我有同样的问题,那么这就是解决方案。
Regards
问候
回答by rg88
It works sometimes so there isn't anything inherently wrong on the PHP end of things (if the path was wrong it would never work... but it does, yes?). So what is causing Loader.php to be periodically inaccessible? I would suspect a permissions problem. Something that is making Loader.php or the directory that it is in inaccessible. Maybe a cron job is setting/reseting permissions? Check that first. See what permissions are when it is working and what they are when it is not.
它有时会起作用,因此在 PHP 端没有任何本质上的错误(如果路径错误,它将永远不会起作用……但确实如此,是吗?)。那么是什么导致 Loader.php 定期无法访问?我怀疑是权限问题。使 Loader.php 或它无法访问的目录的东西。也许 cron 作业正在设置/重置权限?先检查一下。查看权限在工作时是什么,在不工作时是什么。
回答by Rasmus
In my case the Zend/Loader.php was not in the PEAR-directory. It should be there, but my webserver was a little raw. But you can insert it in the library/Zend directory as well.
就我而言,Zend/Loader.php 不在 PEAR 目录中。它应该在那里,但我的网络服务器有点原始。但是您也可以将它插入到 library/Zend 目录中。
But indeed this does not answer why your problem occurs only sometimes.
但确实这并不能回答为什么您的问题只是有时会出现。
回答by cdnicoll
I had this error as well when I was working with PHPUnit 3.5.5. My main application script loaded the zend framework fine, however the test class ran into errors.
当我使用 PHPUnit 3.5.5 时,我也遇到了这个错误。我的主应用程序脚本很好地加载了 zend 框架,但是测试类遇到了错误。
My solution was to add the following to the test class
我的解决方案是将以下内容添加到测试类中
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'classes');
require_once 'ThemeWidgets.php';
require_once 'PHPUnit/Framework.php';
require_once '../../library/Zend/Loader/AutoLoader.php';
class ThemeWidgetsTest extends PHPUnit_Framework_TestCase
{
public function setUp() {
Zend_Loader_Autoloader::getInstance();
}
...

