每个php-fpm池都有自己的内存池吗?

Rya*_*yan 7 php opcache

假设我正在使用PHP 5.5操作码缓存,并设置

opcache.memory_consumption=128

如果我在php-fpm中有4个池,那么4个池中的每个池共享128MB的缓存,或者它们是否会为每个池拥有128M的opcache?

Ale*_*ruk 6

如果您对池之间使用的高速缓存如何进行简单测试有任何疑问.

技术很简单.在不同的www-dir上创建2个fpm-pool,例如8081和8082端口以及2个文件index.phpcheck.php,内容相同:

<?php
echo "<pre>\n";
var_dump(opcache_get_status());
Run Code Online (Sandbox Code Playgroud)

首先重新启动你的php-fpm的服务,然后运行第一个池localhost:8081/index.php,然后localhost:8082/check.php.["scripts"]输出后检查部分.我有下一个结果:

本地主机: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)
    }
  }
Run Code Online (Sandbox Code Playgroud)

本地主机: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)
    }
  }
Run Code Online (Sandbox Code Playgroud)

如您所见,第二个池已经在缓存中有index.php,所以答案是所有4个池将共享128MB缓存.


rai*_*7ow 0

由于 OpCache 本质上与 APC 的工作方式相同(通过将预编译的脚本字节码存储在共享内存中),并且已确认,如果 php-fpm 池由同一主进程启动,则 APC 操作码缓存在它们之间共享,因此将占用 128 MB也在 4 个池之间共享。