包含变量的 APC 缓存

发布于 2024-07-26 00:09:17 字数 304 浏览 9 评论 0原文

我一直在对 PHP 的 APC 缓存进行一些研究,发现条件包含不起作用。 比如:

if($a) {
    include('a.php');
} else {
    include('b.php');
}

我的问题是:我可以用变量包含来解决这个问题吗? 如:

if($a) {
    $file = 'a.php';
} else {
    $file = 'b.php';
}
include($file);

后面的代码APC缓存会成功吗?

I have been doing some research on APC Caching with PHP and found that conditional includes just don't work. Like:

if($a) {
    include('a.php');
} else {
    include('b.php');
}

My question is: Can I get around this with variable includes? Such as:

if($a) {
    $file = 'a.php';
} else {
    $file = 'b.php';
}
include($file);

Would the latter code be APC-cached successfully?

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

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

发布评论

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

评论(3

屋顶上的小猫咪 2024-08-02 00:09:17

APC 仍会缓存该文件,只是在解析您的应用程序的后期阶段。 如果可能的话,建议始终包含两者。

如果您受条件包含的束缚,您应该考虑也许这根本不是什么大问题。 :)

APC will still cache the file, just at a later stage in parsing your app. It's recommended to always include both instead if this is possible.

If you are tied to the conditional includes, you should consider that maybe this is not a big deal at all. :)

葬花如无物 2024-08-02 00:09:17

APC 包包含一个文件 apc.php (我认为它最终位于 /usr/share/doc/ 下的某个位置,因此请复制一份),该文件将显示正在缓存的文件(您需要编辑它并设置查看完整路径的密码)-您是否确定它不起作用,或者您是否正在摆脱围绕 APC 的中文窃窃私语?

The APC package includes a file, apc.php (it ends up somewhere under /usr/share/doc/, I think, so take a copy), that will show you what files are being cached (you need to edit it and set a password to see full path) - do you know for definite it's not working, or are you going off the chinese-whispers that seem to surround APC?

风吹雪碎 2024-08-02 00:09:17

现在看到这篇文章。
认为这可能对某人有用。

使用 APC 时,如果使用 apc.stat=0,则相对路径include、require 等中将不起作用
您需要使用绝对路径。

例如:
考虑名为 myfolder 的文件夹内的脚本。

相对路径会导致错误:

<?php include 'script2.php'; ?>

请改为使用绝对路径:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/myfolder/script2.php'; ?>

请参阅以下链接了解更多信息:
https://bugs.php.net/bug.php?id=59493
http://www.phpbb.com /community/viewtopic.php?f=46&t=2112260&p=12919262#p12919262

Saw this post now.
Thought it might be useful for someone.

While using APC, if apc.stat=0 is used, then relative paths won't work in include, require etc.
You need to use absolute paths.

Eg:
Consider a script inside a folder named myfolder.

Relative paths will cause errors:

<?php include 'script2.php'; ?>

Instead use absolute path:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/myfolder/script2.php'; ?>

Refer the following links for more:
https://bugs.php.net/bug.php?id=59493
http://www.phpbb.com/community/viewtopic.php?f=46&t=2112260&p=12919262#p12919262

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