PHP APC - 生产服务器上的页面刷新后缓存的数据丢失
我在生产服务器上使用 APC 扩展。我添加了以下代码:
$tmp = apc_fetch('pe_cache_test');
apc_store('pe_cache_test', ($tmp === false) ? 0 : $tmp + 1);
...并注意到“pe_cache_test”对于进一步的请求仍然为空。这是正常行为吗,例如由于多个 php 实例?如果每个请求的缓存数据都会丢失,APC 如何提高性能?
如果这种行为不是有意的,我在哪里可以找到问题的根源?
谢谢, Fishbone
编辑 2:
我的主机提供商证实了我的假设。服务器上使用FCGI,因此内存不能共享。这难道不是一个基本问题,并且使得 APC 对于许多生产服务器来说毫无价值吗?正是因为这个原因,我想知道为什么没有人能回答我的问题。即使是解决方法或一些提示也会有很大的帮助。
编辑:
配置和版本:
PHP版本:5.2.16
APC-config(请注意,我使用的是httpd使用的php.ini,但从cli运行phpinfo(),因此“APC支持”设置为“禁用”)
APC Support => disabled
Version => 3.1.3p1
MMAP Support => Enabled
MMAP File Mask =>
Locking type => pthread mutex Locks
Revision => $Revision: 286798 $
Build Date => Jan 4 2011 13:07:19
Directive => Local Value => Master Value
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.shm_segments => 1 => 1
apc.shm_size => 30 => 30
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On
我的主机提供商仅提供用于打开/关闭 APC 的复选框,因为我们在托管服务器上运行网站。
I use the APC extension on our production server. I added this code:
$tmp = apc_fetch('pe_cache_test');
apc_store('pe_cache_test', ($tmp === false) ? 0 : $tmp + 1);
... and noticed that 'pe_cache_test' remains empty for further requests. Is this normal behavior, e.g. due to multiple php-instances? If cache-data was lost for every request, how would APC being able to improve performance?
If this behavior is not intended, where can I possibly find the source of problems?
Thanks,
fishbone
Edit 2:
My host-provider confirmed my assumptions. FCGI is used on the server and therefore memory cannot be shared. Isn't this an elementary problem and makes APC absolutely worthless for many production servers? Exactly for this reason I'm wondering why nobody can answer my question. Even a workaround or some hints would be a great help.
Edit:
config and versions:
PHP-version: 5.2.16
APC-config (note that I'm using the php.ini used by httpd but running phpinfo() from cli, therefore "APC Support" is set to "disabled")
APC Support => disabled
Version => 3.1.3p1
MMAP Support => Enabled
MMAP File Mask =>
Locking type => pthread mutex Locks
Revision => $Revision: 286798 $
Build Date => Jan 4 2011 13:07:19
Directive => Local Value => Master Value
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.shm_segments => 1 => 1
apc.shm_size => 30 => 30
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On
My host-provider only provides a checkbox for switching APC on/off, because we are running the website on a managed server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 PHP 配置为 CGI,您将无法使用 APC,在这种情况下请使用 memcached。
APC 仅适用于已配置为模块的 PHP(例如 Apache mod_php)
If your PHP is configured as CGI, you will not be able to use APC, use memcached for this case.
The APC is only for PHP which has been configured as module (for ex. Apache mod_php)