假设我将数据缓存在PHP数组中的PHP文件中,如下所示:
/cache.php
<?php return (object) array(
'key' => 'value',
);
Run Code Online (Sandbox Code Playgroud)
我包括这样的缓存文件:
<?php
$cache = include 'cache.php';
Run Code Online (Sandbox Code Playgroud)
现在,问题是APC会在内存中自动缓存缓存文件吗?我的意思是作为典型的操作码缓存,就像所有.php文件一样.
如果我以不同方式存储数据,例如以JSON格式(cache.json),APC将不会自动缓存数据?
会apc_store
更快/更好吗?
per*_*lis 10
不要将APC的缓存能力与优化中间代码和缓存编译代码的能力相结合.APC提供两种不同的东西:
让我们看一下(1)的例子:假设你有一个需要1秒钟的数据结构来计算:
function calculate_array() {
sleep(1);
return array('foo' => 'bar');
}
$data = calculate_array();
Run Code Online (Sandbox Code Playgroud)
您可以存储其输出,这样您就不必再次调用慢的calculate_array():
function calculate_array() {
sleep(1);
return array('foo' => 'bar');
}
if (!apc_exists('key1')) {
$data = calculate_array();
apc_store('key1', $data);
} else {
$data = apc_fetch('key1');
}
Run Code Online (Sandbox Code Playgroud)
这将比原来的1秒快得多,远远低于原来的1秒.
现在,对于上面的(2):让APC运行不会超过1秒,这是calculate_array()需要的时间.但是,如果您的文件另外需要(比如说)100毫秒来初始化和执行,那么只需启用APC就可以使其需要(大约)20毫秒.因此初始化/准备时间增加了80%.这可以在生产系统中产生很大的不同,因此简单地安装APC会对脚本的性能产生明显的积极影响,即使您从未明确调用其任何功能
归档时间: |
|
查看次数: |
7045 次 |
最近记录: |