How to share APC cache between several PHP process

2019-01-21 09:34发布

I'm currently running several copies of PHP/FastCGI, with APC enabled (under Apache+mod_fastcgi, if that matters). Can I share cache between the processes? How can I check if it's shared already? (I think the apc.mmap_file_mask ini setting might be involved, but I don't know how to use it.)

(One of the reasons I think its not shared at the moment is that the apc.mmap_file_mask, as reported by the apc.php web interface flips between about 3 different values as I reload.)

3条回答
Explosion°爆炸
2楼-- · 2019-01-21 10:08

The cache should be shared between processes. You should be seeing the same value for the mmap file between phpinfo() and apc.php invocations. It is working for me with the suggested default APC configuration settings:

extension="apc.so"
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask="/tmp/apc.XXXXXX"
apc.enable_cli=1

You may want to post your settings. I've seen warnings that the mmap_file_mask must be exactly one of the values they allow. So if you are missing one of those Xs there is no telling what you will get.

Maybe it involves your fastcgi+apache configuration.

查看更多
forever°为你锁心
3楼-- · 2019-01-21 10:10

APC does not currently share its cache between multiple php-cgi workers running under fastcgi or fcgid. See this feature request for details: "this behaviour is the intended one as of now".

One workaround is to allow PHP to manage its own workers. You can do this using the PHP_FCGI_CHILDREN environment variable in your wrapper script (plenty of examples all over the web for that). You should also stop fastcgi/fcgid from spawning more than one PHP process if you want to use this method.

The disadvantage with PHP_FCGI_CHILDREN is that its management of the workers is not as good as that provided by fcgid/fastcgi.

So, there we are. APC in a fcgid/fastcgi environment means giving each PHP worker their own cache, or disabling fcgid/fastcgi's process spawning in favor of PHP's built-in management. Let's hope this changes in the future.

查看更多
时光不老,我们不散
4楼-- · 2019-01-21 10:14

While it's not perfect the method Domster suggested is the best. I've been doing this for a short time on some low volume sites without errors. I wrote up a detailed explanation on how to set up mod_fastcgi with a shared opcode cache last night.

I found it very important to use mod_fastcgi rather than the newer mod_fcgid because mod_fcgid will only send one request at a time to the PHP process regardless of how many children PHP has spawned via PHP_FCGI_CHILDREN.

查看更多
登录 后发表回答