我必須錯過一些明顯的東西。我的APC安裝正確,並顯示在phpinfo()就好了。我目前正在apache上運行帶有APC 3.1.13的php 5.4.20。這是一個cPanel安裝,因此請牢記這一點。PHP的APC緩存不會保留任何變量
主要問題是緩存正在工作,但僅限於頁面加載期間。如果我跑
<?php
apc_store('foo', 'bar');
echo apc_fetch('foo');
?>
將回聲出變量,但如果我註釋掉apc_store並再次運行代碼,什麼也不顯示和顯示的var_dump布爾(假);
我試過這段代碼,如果我在做一些愚蠢的事情,而且這也不起作用。它總是顯示
// 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的配置如下:「STR不是從緩存...節約發現」 ......
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已經安裝了督促服務器上的工作。它實際上是在按照應有的方式工作。所以我運行了php_sapi_name(),在prod服務器上它是apache2handler,在開發服務器上(我正在使用的那個),它使用的是cgi-fcgi,這可能是問題的原因。由於我使用的是cPanel,我應該能夠簡單地將PHP「Handler」從suPHP更改爲DSO,並且在此之後它應該可以工作。 prod服務器不使用cPanel,只是很好的舊時尚....呃.....非cPanel的東西,使其工作。
爲什麼將它存儲在APC中,而不是在會話中 – Machavity
您在PHP中運行什麼模式? APC在FastCGI下奇怪地工作,在CGI下根本不工作。 – duskwuff
@Machavity我們已經在會話中存儲了一堆東西,我正在查看的數據最適合在中央緩存下使用。 – n0nag0n