Let say I am using the PHP 5.5 opcode cache, and set
opcache.memory_consumption=128
, if I have 4 pools in php-fpm, will each of the 4 pool share 128MB of cache, or will they own 128M opcache for each pool?
If you have any doubts about how cache memory used between pools make a simple test.
Technique is quite simple. Create 2 fpm-pools on different www-dir listening for example 8081 and 8082 ports and 2 files index.php and check.php with identical content:
<?php
echo "<pre>\n";
var_dump(opcache_get_status());
Firstly restart your php-fpm service, then run first pool localhost:8081/index.php
, then localhost:8082/check.php
. After this check ["scripts"]
section in output. I've got next results:
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)
}
}
As you see second pool already has index.php in cache, so answer is all 4 pools will share 128MB of cache.
As mentioned by raina77ow through link that 128 MB will be shared betweeen 4 Pools
Adding to that, as mentioned in official documentation
; Sets how much memory to use
opcache.memory_consumption=128
opcache.memory_consumption sets the memory limit that will be used no matter how many pools you use, it will get shared accordingly.
As OpCache essentially works the same way as APC does (by storing precompiled script bytecode in shared memory), and it's confirmed that APC opcode cache is shared between php-fpm pools if they're started by the same master process, 128 MB will be shared between 4 pools as well.