PHP突然停止在当前目录中搜索文件

发布于 2024-11-06 16:13:41 字数 616 浏览 0 评论 0原文

所以我今天遇到了一些非常奇怪的事情。

我已将 PHP APC 更新到最新版本并重新启动 apache。然后突然 apache 中的所有脚本开始抱怨无法找到所需的文件。

我通常会这样:

require_once 'Abstract.php'

考虑到 Abstract.php 与其他脚本位于同一目录中,

。错误所在:

PHP 警告: require_once(Abstract.php) [function.require-once]: 无法打开流:没有这样的文件或 data.php 中第 411 行 PHP 的目录 致命错误:require_once() [function.require]: 无法打开所需的“Abstract.php” (include_path='/var/www/application/../library:/var/www/library:.:/usr/share/php:/usr/share/pear') 在 data.php 的第 411 行

,您可以看到当前目录 (.) 包含在执行的 include_path 中。为什么会发生这种情况?有人见过吗?

So I came up against something really strange today.

I've updated my PHP APC to the latest version and restarted apache. And then suddenly all scripts in apache starting complaining about not being able to find required files.

I would usually have:

require_once 'Abstract.php'

considering that Abstract.php is on the same directory as the other script.

The errors where:

PHP Warning:
require_once(Abstract.php) [function.require-once]:
failed to open stream: No such file or
directory in data.php on line 411 PHP
Fatal error: require_once() [function.require]:
Failed opening required 'Abstract.php'
(include_path='/var/www/application/../library:/var/www/library:.:/usr/share/php:/usr/share/pear')
in data.php on line 411

As you can see the current directory (.) is included in the include_path of the execution. Why did this happen? Has anyone seen it before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-11-13 16:13:41

AFAIK,. 表示 PHP 二进制文件所在的目录。 require*include* 函数考虑当前工作目录,可以通过 chdir() 修改该目录。

正如 cwallenpoole 所建议的,尝试使用 __DIR__ 常量:

require_once __DIR__ . '/Abstract.php';

如果也失败,则意味着其他地方配置错误。如果它有效,则可能意味着当前执行的 PHP 线程将其工作目录设置为不同的,您需要更改当前工作目录或修改 require 语句以使用绝对路径。

另外,您是否考虑过使用自动加载回调?这样您就可以通过单一入口来搜索课程。

AFAIK, the . denotes the directory where the PHP binary resides. require* and include* functions take into account the current working directory, which can be modified via chdir().

As was suggested by cwallenpoole, try using the __DIR__ constant:

require_once __DIR__ . '/Abstract.php';

If that also fails, it means there's a misconfiguration elsewhere. If it works, it probably means the current executing PHP thread has its working directory set to a different and you need to either change the current working directory or modify the require statements to use absolute paths.

Also, have you considered using an autoload callback? That way you have a single point of entry for searching for classes.

如歌彻婉言 2024-11-13 16:13:41

好吧,我最终想通了,不过我应该分享,以防其他人遇到和我一样的麻烦。

我以前有APC 3.0.x,升级到3.1.8。 3.1.8 上的 APC 似乎有一个错误,破坏了 PHP 的包含/要求。

请参阅此处的相关链接:http://pecl.php.net/bugs/bug。 php?id=22687

感谢大家的快速反馈:)

Ok, I figured it out eventually and though I should share in case anyone else gets in the same trouble as me.

I used to have APC 3.0.x and upgraded to 3.1.8. As it seems APC on 3.1.8 has a bug that breaks include/requires of PHP.

See relative link here: http://pecl.php.net/bugs/bug.php?id=22687

Thanks everyone for the quick feedback :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文