php 在FastCGI下运行时如何在多个PHP进程之间共享APC缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/598444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to share APC cache between several PHP processes when running under FastCGI?
提问by mjs
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_maskini setting might be involved, but I don't know how to use it.)
我目前正在运行多个 PHP/FastCGI 副本,并启用 APC(在 Apache+mod_fastcgi 下,如果这很重要)。我可以在进程之间共享缓存吗?如何检查它是否已共享?(我认为apc.mmap_file_mask可能涉及到ini设置,但我不知道如何使用它。)
(One of the reasons I think its notshared 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.)
(我认为它目前没有共享的原因之一是,apc.mmap_file_mask当我重新加载时,apc.php 网络界面报告的 将在大约 3 个不同的值之间翻转。)
采纳答案by Dominic Scheirlinck
APC does notcurrently share its cache between multiple php-cgi workers running under fastcgi or fcgid. See this feature requestfor details: "this behaviour is the intended one as of now".
APC当前不在fastcgi 或 fcgid 下运行的多个 php-cgi 工作程序之间共享其缓存。有关详细信息,请参阅此功能请求:“此行为是目前预期的行为”。
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.
一种解决方法是允许 PHP 管理自己的工作人员。您可以使用包装脚本中的 PHP_FCGI_CHILDREN 环境变量来执行此操作(网络上有大量示例)。如果您想使用这种方法,您还应该阻止 fastcgi/fcgid 产生多个 PHP 进程。
The disadvantage with PHP_FCGI_CHILDREN is that its management of the workers is not as good as that provided by fcgid/fastcgi.
PHP_FCGI_CHILDREN 的缺点是它对 worker 的管理不如 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.
所以,我们来了。fcgid/fastcgi 环境中的 APC 意味着为每个 PHP 工作程序提供自己的缓存,或者禁用 fcgid/fastcgi 的进程生成以支持 PHP 的内置管理。让我们希望这在未来有所改变。
回答by blt04
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 cachelast night.
虽然它并不完美,但 Domster 建议的方法是最好的。我在一些低容量网站上做了很短的时间,没有错误。昨晚我写了一篇关于如何使用共享操作码缓存设置 mod_fastcgi的详细说明。
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.
我发现使用 mod_fastcgi 而不是较新的 mod_fcgid 非常重要,因为 mod_fcgid 一次只会向 PHP 进程发送一个请求,而不管 PHP 通过 PHP_FCGI_CHILDREN 产生了多少子代。
回答by carson
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:
缓存应该在进程之间共享。您应该在 phpinfo() 和 apc.php 调用之间看到 mmap 文件的相同值。它使用建议的默认 APC 配置设置对我有用:
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.
您可能想发布您的设置。我已经看到警告说 mmap_file_mask 必须恰好是它们允许的值之一。因此,如果您错过了其中一个 X,则无法确定您会得到什么。
Maybe it involves your fastcgi+apache configuration.
可能涉及到你的fastcgi+apache配置。

