包含变量的 APC 缓存
我一直在对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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. :)
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?
现在看到这篇文章。
认为这可能对某人有用。
使用 APC 时,如果使用
apc.stat=0
,则相对路径在include、require
等中将不起作用您需要使用绝对路径。
例如:
考虑名为 myfolder 的文件夹内的脚本。
相对路径会导致错误:
请改为使用绝对路径:
请参阅以下链接了解更多信息:
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 ininclude, require
etc.You need to use absolute paths.
Eg:
Consider a script inside a folder named myfolder.
Relative paths will cause errors:
Instead use absolute path:
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