How to share APC cache between several PHP processes when running under FastCGI?

mjs picture mjs · Feb 28, 2009 · Viewed 25.1k times · Source

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.)

Answer

Dominic Scheirlinck picture Dominic Scheirlinck · Jun 17, 2009

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.