我必须遗漏一些明显的东西。我的 APC 已正确安装并在 phpinfo() 中显示得很好。我目前在 apache 上运行 php 5.4.20 和 APC 3.1.13。这是一个 cpanel 安装,所以也要记住这一点。
主要问题是缓存正在工作,但仅在页面加载期间有效。如果我跑
<?php
apc_store('foo', 'bar');
echo apc_fetch('foo');
?>
它会回显变量,但是如果我注释掉 apc_store 并再次运行代码,则什么都没有显示,并且 var_dump 显示 boolean(false);
我也尝试过这段代码,以防我做一些愚蠢的事情,这也不起作用。它总是显示“str not found from cache...正在保存”
// Check if str found from cache
if (apc_exists('str')) {
// Print str from cache
echo "str from cache: ", apc_fetch('str'), "<br />";
// Clear cache
apc_clear_cache('user');
// Try to fetch str again
echo "str from cache, after user cache is cleared: ", "<br />";
var_dump(apc_fetch('str'));
}
else {
// Save str to cache and set ttl 120 seconds
echo 'str not found from cache...saving', "<br />";
$str = "This is just test";
apc_store('str', $str, 120);
}
我的apc配置如下...
apc
APC Support => disabled
Version => 3.1.13
APC Debugging => Disabled
MMAP Support => Enabled
MMAP File Mask =>
Locking type => pthread read/write Locks
Serialization Support => broken
Revision => $Revision: 327136 $
Build Date => Oct 17 2013 16:47:57
Directive => Local Value => Master Value
apc.cache_by_default => Off => Off
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.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 512 => 512
apc.shm_strings_buffer => 4M => 4M
apc.slam_defense => Off => Off
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
我必须遗漏一些明显的东西......任何帮助表示赞赏。TIA
编辑
所以我检查了它的 apc 是否在已经安装了 apc 的 prod 服务器上正常工作。事实上,它正在按应有的方式工作。所以我运行了 php_sapi_name(),在 prod 服务器上它是 apache2handler,在 dev 服务器(我目前正在使用的那个)上,它使用的是 cgi-fcgi,这可能是问题的原因。由于我使用的是 cPanel,我应该能够简单地将 PHP“处理程序”从 suPHP 更改为 DSO,之后它应该可以工作。prod 服务器不使用 cpanel,只是很好的旧时尚......呃......非 cPanel 的东西让它工作。