如何检查 APC 操作码缓存在 PHP 中是否正常工作?
我正在使用启用了 APC 缓存的 PHP:
apc.cache_by_default => On
apc.enabled => On
apc.ttl => 7200
现在我如何知道它是否 100% 使用操作码缓存。
例如,假设我有这个 PHP 文件:
<?php
echo "Hi there";
?>
现在运行该文件后,让我们将其更改为 echo "Bye There";
自从 TTL 以来,它不应该 echo "Hi There"吗? 7200秒还没结束?我说得对吗?如果是这样,为什么它会回响“再见”?如果我错了,即使在更改文件后,如何强制它使用操作码缓存?
I am using PHP with APC cache enabled:
apc.cache_by_default => On
apc.enabled => On
apc.ttl => 7200
Now how can I know if it is using the opcode cache 100%.
For example, let us say that I have this PHP file:
<?php
echo "Hi there";
?>
Now after running this file, let us change it to echo "Bye there";
Shouldn't it echo "Hi there" since the TTL of 7200 seconds is not over yet? Am I right? If so, why does it echo "Bye there"? And if I am wrong how can I force it to use the opcode cache even after changing the file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能找到的判断 APC 是否正常工作的最简单方法是创建一个包含此代码的新 PHP 文件...
它将 apc_cache_info() 的内容转储到屏幕上(小心,在大型实时站点上,这可能是大量数据!)。
每次重新加载此 PHP 文件时,您都应该看到
num_hits
增加,这意味着操作码缓存已被使用。未命中表明 APC 必须从源代码重新编译文件(通常在每次更改时完成)。要获得此信息的更好界面,您可以使用 APC 附带的
apc.php
文件。我使用此控制台命令将其复制到我的网站目录(您的文件夹位置可能有所不同)...在浏览器中运行此文件将为您提供漂亮的颜色和图形!
有关详细信息,请参阅此链接:
http://www.electrictoolbox.com/apc-php-cache-information/< /a>
The simplest way that I could find to tell whether APC is working was to create a new PHP file containing this code...
It dumps the contents of apc_cache_info() to the screen (be careful, on a large, live site this could be lots of data!).
Every time you reload this PHP file, you should see
num_hits
increase, meaning that the opcode cache was used. A miss indicates that APC had to recompile the file from source (usually done on every change).For a nicer interface to this information you can use the
apc.php
file that comes with APC. I copied this to my website directory using this console command (your folder locations may differ)...Running this file in your browser gives you nice colours and graphs!
See this link for further info:
http://www.electrictoolbox.com/apc-php-cache-information/
我认为您不想在生产中执行此操作,但您始终可以使用
apc_cache_info()
。请注意,这将遍历缓存的每个文件以检查指定的文件,因此效率不高。
至于您的具体问题,APC 会在文件更改时自动使文件的缓存失效。因此,当您编辑文件时,APC 会默默地检测到这一点并提供新文件。您可以通过设置
apc.stat = 来禁用此功能0
。I don't think you'll want to do it in production, but you could always use
apc_cache_info()
.Note that this will iterate over every single file that's cached checking for the specified one, so it's not efficient.
And as far as your specific question, APC will automatically invalidate the cache for a file when it changes. So when you edit the file, APC silently detects this and serves the new file. You can disable this by setting
apc.stat = 0
.通常,APC 会检查所请求的文件自缓存以来是否已被修改。您可以使用 apc.stat 来控制它。
Normally APC checks if the requested file has been modified since it's been cached. You can control this with apc.stat.