【发布时间】:2014-01-01 10:53:57
【问题描述】:
假设我正在使用 PHP 5.5 操作码缓存,并设置
opcache.memory_consumption=128
,如果我在 php-fpm 中有 4 个池,这 4 个池中的每一个会共享 128MB 的缓存,还是每个池拥有 128M 的 opcache?
【问题讨论】:
假设我正在使用 PHP 5.5 操作码缓存,并设置
opcache.memory_consumption=128
,如果我在 php-fpm 中有 4 个池,这 4 个池中的每一个会共享 128MB 的缓存,还是每个池拥有 128M 的 opcache?
【问题讨论】:
如果您对池之间使用的缓存内存有任何疑问,请做一个简单的测试。
技术很简单。在不同的 www-dir 上创建 2 个 fpm 池,例如 8081 和 8082 端口以及 2 个文件 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 的缓存。
【讨论】:
raina77ow 通过 link 提到 128 MB 将在 4 个池之间共享
除此之外,如官方文档中所述
; Sets how much memory to use
opcache.memory_consumption=128
opcache.memory_consumption 设置将使用的内存限制,无论您使用多少个池,都会相应地共享。
【讨论】:
php_admin_value/php_value 等设置每个池的 PHP 选项。如果您为opcache.memory_consumption 或opcache.interned_strings_usage 执行此操作,则实际可用内存不会增加 - 相反,FPM 的 php.ini 和池配置中的相应值之间的差异只会添加到 used_memory 计数中opcache_get_status()。这让我很困惑,我花了一段时间才意识到我实际上必须更改 php.ini 中的值。
由于 OpCache 本质上与 APC 的工作方式相同(通过将预编译的脚本字节码存储在 共享内存 中),并且如果 APC 操作码缓存在 php-fpm 池之间共享,则为 confirmed由同一个主进程重新启动,128 MB 将在 4 个池之间共享。
【讨论】: