假设我使用的是PHP 5.5操作码缓存,并设置
opcache.memory_consumption=128
,如果我在php-fpm中有4个池,那么这4个池中的每一个都会共享128MB的缓存吗?或者他们会为每个池拥有128M的操作缓存吗?
如果您对池之间使用的缓存内存有任何疑问,请进行简单的测试。
技术很简单。在不同的www目录上创建两个fpm池,例如8081和8082端口以及两个内容相同的文件index.php和check.php:
<?php
echo "<pre>n";
var_dump(opcache_get_status());
首先重新启动php-fpm服务,然后运行第一个池localhost:8081/index.php
,然后运行localhost:8082/check.php
。检查输出中的["scripts"]
部分之后。我有下一个结果:
localhost:8081/index.php
["scripts"]=>
array(1) {
["/usr/share/nginx/html/index.php"]=>
array(6) {
["full_path"]=>
string(31) "/usr/share/nginx/html/index.php"
["hits"]=>
int(0)
["memory_consumption"]=>
int(1032)
["last_used"]=>
string(24) "Mon Dec 23 23:38:35 2013"
["last_used_timestamp"]=>
int(1387827515)
["timestamp"]=>
int(1387825100)
}
}
localhost:8082/check.php
["scripts"]=>
array(2) {
["/usr/share/nginx/html1/check.php"]=>
array(6) {
["full_path"]=>
string(32) "/usr/share/nginx/html1/check.php"
["hits"]=>
int(0)
["memory_consumption"]=>
int(1056)
["last_used"]=>
string(24) "Mon Dec 23 23:38:47 2013"
["last_used_timestamp"]=>
int(1387827527)
["timestamp"]=>
int(1387825174)
}
["/usr/share/nginx/html/index.php"]=>
array(6) {
["full_path"]=>
string(31) "/usr/share/nginx/html/index.php"
["hits"]=>
int(0)
["memory_consumption"]=>
int(1032)
["last_used"]=>
string(24) "Mon Dec 23 23:38:35 2013"
["last_used_timestamp"]=>
int(1387827515)
["timestamp"]=>
int(1387825100)
}
}
正如您所看到的,第二个池的缓存中已经有index.php,所以答案是所有4个池将共享128MB的缓存。
正如raina77通过链接所提到的,128 MB将在4个池之间共享
此外,如官方文件中所述
; Sets how much memory to use
opcache.memory_consumption=128
opcache.memory_sumption设置将要使用的内存限制,无论您使用多少个池,它都将相应地被共享。
由于OpCache的工作方式与APC基本相同(通过将预编译的脚本字节码存储在共享内存中),并且已确认如果php fpm池由同一主进程启动,则APC操作码缓存将在它们之间共享,因此4个池之间也将共享128MB。