合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# APCu扩展 APCU的前身是APC,APC的主要用途有两项: 1. 将PHP代码编译之后所产生的bytecode暂存在共享内存内供重复使用,以提升应用的运行效率。(Opcode Cache) 2. 提供用户数据缓存功能。(User Data Cache) 其中第一点是其主要功能,因为PHP的运行机制——每次接受一个请求时都要初始化所有的资源(将源代码转换成Opcode(即001011机器操作吗),……),执行代码,然后释放资源;所以启用Opcache Cache后,在第一次请求时将编译后的机器操作码暂存在共享内存内供重复使用,这样就可以在初始化资源阶段减少CPU和内存的消耗。 但是PHP从PHP 5.5开始,使用ZendOptimizerPlus(更名为Opcache)作为内置的Opcode Cache实现。所以现在APCU的主要功能便不再有意义了,而且其官方也随后表示不再维护APC了。 虽然apc可以通过关闭Opcache Cache而只使用用户数据缓存功能但是APC的User Data Cache使用的存储机制是和Opcode Cache一样的, 这样的场景要求数据严格正确, 所以锁会比较多,因此APCU作为缓存用户数据的扩展被启用。 他的作用和redis和memcached重合,测试表明, APC的User Data Cache的效率和本地memcached几乎相当(在单机性能上,APCu通常比Memcached更高。memcached本身的设计就是为了分布式应用,大规模内存缓存,集群,易扩展等,如果只有一台服务器且内存足够缓存用户数据时推荐apcu) APCU缓存和memcahce/redis不一样的地方。你通过memcache/redis存储一个数据,在缓存有效期内,同一机器上的不同的PHP进程(FPM+CLI)都是能够取到这份数据的。 对的,注意关键字 “同一机器上的不同的PHP进程”,对于APCU而言,PHP-FPM(PHP5.3.3+)模式下所有的php-fpm进程(即使是不同的pool)属于同一个父进程,所以是可以共享缓存数据的;但是cli(命令行)模式每次都是单独一个全新进程,因而和php-fpm模式的进程是不能共享缓存数据的。所以如果你的业务场景需要在cli和php-fpm两种模式下共享数据一定要小心了,可能memcache或者redis才是你更好的选择 **APCu 配置选项** 名字默认可修改范围说明apc.enabled"1"PHP\_INI\_SYSTEM启用缓存扩展apc.shm\_segments"1"PHP\_INI\_SYSTEM分配**共享内存块**的数量(建议值为1)apc.shm\_size"32M"PHP\_INI\_SYSTEM设置每个**共享内存块**的大小(以MB为单位,建议值为128~256)apc.entries\_hint"4096"PHP\_INI\_SYSTEM关于可能存储的不同变量的数量“提示”。如果不确定,设置为零或省略apc.ttl"0"PHP\_INI\_SYSTEM设置缓存超时时间,单位是秒。0表示永不超时。建议值为7200~36000。apc.gc\_ttl"3600"PHP\_INI\_SYSTEM缓存条目在垃圾回收表中能够存在的秒数,此值提供了一个安全措施,即使一个服务器进程在执行缓存的源文件时崩溃,而且该源文件已经被修改,为旧版本分配的内存也不会被回收,直到达到此ttl值为止,设置为0禁用此功能apc.mmap\_file\_maskNULLPHP\_INI\_SYSTEM如果在安装模块时使用–enable-mmap(默认启用)为apc编译了mmap(映射)支持, 这里的值就是传递给mmap模块的mktemp风格的文件掩码(建议值为"/tmp/apc.xxxxxx"),以确定内存映射区域是文件支持的还是共享内存支持的。 对于直接文件支持的内存映射,将它设置为/tmp/apc。XXXXXX(正好6x)。 要使用posix风格的shm\_open/mmap就需要设置成"/apc.shm.xxxxxx"的样子。例如/ apc.shm。 您还可以将它设置为/dev/zero,以使用内核的/dev/zero接口来访问匿名映射的内存。 不定义它将强制生成一个匿名的mmap(映射)。 它将只使用一个内存段,这与使用多个内存段的SHM (SysV共享内存)支持构建APCu不同。MMAP不像/proc/sys/kernel/ shmmaxde那样有最大限制。一般来说,MMAP支持是被推荐的,因为它将在重新启动web服务器时更快地回收内存,并且总而言之,在启动时减少了内存分配的影响。apc.slam\_defense"1"PHP\_INI\_SYSTEM在非常繁忙的服务器上,无论是启动服务还是修改文件,都可能由于多个进程企图同时缓存一个文件而导致竞争条件。这个指令用于设置进程在处理未被缓存的文件时跳过缓存步骤的百分率。比如设为75表示在遇到未被缓存的文件时有75%的概率不进行缓存,从而减少碰撞几率。设为 0 禁用这个特性。apc.enable\_cli"0"PHP\_INI\_SYSTEM主要用于测试和调试,通过设置此选项,可以为cli版本的php启用apc功能。在正常情况下,在每个CLI请求上创建、填充和销毁APC缓存并不理想,但是对于各种测试场景,能够轻松地为CLI版本的PHP启用APC是很有用的apc.use\_request\_time"1"PHP\_INI\_ALL为生存时间TTL使用SAPI请求启动时间apc.serializer"default"PHP\_INI\_SYSTEM用于配置APC以使用第三方序列化程序apc.coredump\_unmap"0"PHP\_INI\_SYSTEM启用APC的信号句柄,例如SIGSEGV信号,当信号写入核心文件。当这些信号被接收,APC将试图取消映射的共享内存段,从核心文件中排除它。此设置可以提高系统的稳定性,当接受到致命的信号或者采用APC的大型共享内存段配置方式 此功能是潜在的危险。如果发生致命错误取消映射一个共享内存段致命的信号句柄, 可能会导致不可预知的结果 虽然有些内核可能会提供了便利,忽略各类共享内存时生成核心转储文件,这些实现可能也忽略了重要的共享内存段,比如 Apache scoreboardapc.preload\_pathNULLPHP\_INI\_SYSTEM可选地,设置APC将在启动时加载缓存数据的目录的路径如果APCu在工作,那么缓存的全计数号(在左边)将显示缓存达到最大容量的次数,并且必须强制清除上一个apc中没有访问的任何条目 ``` <pre class="calibre10">``` <span class="token">//修改php.ini加入如下内容[请根据环境自行调整]:</span> extension<span class="token1">=</span> <span class="token2">"apcu.so"</span> <span class="token3">;</span> <span class="token3">;</span>开启功能 apc<span class="token3">.</span>enabled<span class="token1">=</span> <span class="token6">1</span> <span class="token3">;</span>为编译器缓冲区分配的共享内存块数量<span class="token3">(</span>建议值为<span class="token6">1</span><span class="token3">)</span>。 apc<span class="token3">.</span>shm_segments<span class="token1">=</span> <span class="token6">1</span> <span class="token3">;</span>每个共享内存块的大小<span class="token3">(</span>以MB为单位,建议值为<span class="token6">128</span><span class="token1">~</span><span class="token6">256</span><span class="token3">)</span>。 apc<span class="token3">.</span>shm_size<span class="token1">=</span> <span class="token6">128</span>M <span class="token3">;</span>优化级别<span class="token3">(</span>建议值为<span class="token6">0</span> <span class="token3">)</span><span class="token3">;</span>正整数值表示启用优化器,值越高则使用越激进的优化。 apc<span class="token3">.</span>optimization<span class="token1">=</span> <span class="token6">0</span> <span class="token3">;</span>Web服务器上可能被包含或被请求的不同源文件的大致数量<span class="token3">(</span>建议值为<span class="token6">1024</span><span class="token1">~</span><span class="token6">4096</span><span class="token3">)</span>。如果不能确定,则设为<span class="token6">0</span>。 apc<span class="token3">.</span>num_files_hint<span class="token1">=</span> <span class="token6">0</span> <span class="token3">;</span>缓冲区中超时时间,单位是秒。<span class="token6">0</span>表示永不超时。建议值为<span class="token6">7200</span><span class="token1">~</span><span class="token6">36000</span>。 apc<span class="token3">.</span>ttl<span class="token1">=</span> <span class="token6">0</span> <span class="token3">;</span>缓存条目在垃圾回收表中超时秒数。 apc<span class="token3">.</span>gc_ttl<span class="token1">=</span> <span class="token6">3600</span> <span class="token">//配置变更后,需重启httpd或者php-fpm服务。</span> ``` ``` ## **函数:** **增** `apcu_add( string $key , mixed $var [, int $ttl = 0 ] ) bool -在数据存储中缓存一个新变量,变量以存在则不会被设置` ``` <pre class="calibre10">``` $bar <span class="token1">=</span> <span class="token2">'BAR'</span><span class="token3">;</span> <span class="token4">apcu_add</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">,</span> $bar<span class="token3">)</span><span class="token3">;</span> <span class="token4">var_dump</span><span class="token3">(</span><span class="token4">apcu_fetch</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">)</span><span class="token3">;</span> <span class="token">//BAR</span> $bar <span class="token1">=</span> <span class="token2">'NEVER GETS SET'</span><span class="token3">;</span> <span class="token4">apcu_add</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">,</span> $bar<span class="token3">,</span><span class="token6">0</span><span class="token3">)</span><span class="token3">;</span> <span class="token4">var_dump</span><span class="token3">(</span><span class="token4">apcu_fetch</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">)</span><span class="token3">;</span><span class="token">//BAR</span> ``` ``` `apcu_add( array $values [, mixed $unused = NULL [, int $ttl = 0 ]] ) : array -在数据存储中缓存多个新变量,变量以存在则不会被设置` ``` <pre class="calibre10">``` <span class="token4">apcu_add</span><span class="token3">(</span><span class="token3">[</span><span class="token2">'foo'</span><span class="token1">=</span><span class="token1">></span><span class="token2">'BAR'</span><span class="token3">,</span><span class="token2">'tool'</span><span class="token1">=</span><span class="token1">></span><span class="token2">'BBT'</span><span class="token3">]</span><span class="token3">)</span><span class="token3">;</span> <span class="token4">apcu_add</span><span class="token3">(</span><span class="token3">[</span><span class="token2">'foo'</span><span class="token1">=</span><span class="token1">></span><span class="token2">'BAR'</span><span class="token3">,</span><span class="token2">'tool'</span><span class="token1">=</span><span class="token1">></span><span class="token2">'BBT'</span><span class="token3">]</span><span class="token3">,</span><span class="token5">null</span><span class="token3">,</span><span class="token6">0</span><span class="token3">)</span><span class="token3">;</span> ``` ``` `apcu_store -在数据存储中缓存一个变量 用法同apcu_add,区别就是他会覆盖存在的缓存变量` - - - - - - **查** `apcu_fetch( mixed $key [, bool &$success ] ) : mixed - 从缓存中获取已存储的变量` ``` <pre class="calibre10">``` $bar <span class="token1">=</span> <span class="token2">'BAR'</span><span class="token3">;</span> <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">,</span> $bar<span class="token3">)</span><span class="token3">;</span> <span class="token4">var_dump</span><span class="token3">(</span><span class="token4">apcu_fetch</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">)</span><span class="token3">;</span><span class="token">//BAR</span> ``` ``` - - - - - - **改** `apcu_cas( string $key , int $old , int $new ) : bool - 用新值更新旧值` ``` <pre class="calibre10">``` <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'foobar'</span><span class="token3">,</span> <span class="token6">2</span><span class="token3">)</span><span class="token3">;</span> <span class="token4">apcu_cas</span><span class="token3">(</span><span class="token2">'foobar'</span><span class="token3">,</span> <span class="token6">2</span><span class="token3">,</span> <span class="token6">1</span><span class="token3">)</span> ``` ``` `apcu_dec( string $key [, int $step = 1 [, bool &$success [, int $ttl = 0 ]]] ) -减少存储的值(递减,必须数值型)` ``` <pre class="calibre10">``` <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">42</span><span class="token3">)</span><span class="token3">;</span> echo <span class="token4">apcu_dec</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> echo <span class="token4">apcu_dec</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">10</span><span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> echo <span class="token4">apcu_dec</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">10</span><span class="token3">,</span> $success<span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> ``` ``` `apcu_inc增加存储的值(递增,必须数值型)` ``` <pre class="calibre10">``` <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">42</span><span class="token3">)</span><span class="token3">;</span> echo <span class="token4">apcu_inc</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> echo <span class="token4">apcu_inc</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">10</span><span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> echo <span class="token4">apcu_inc</span><span class="token3">(</span><span class="token2">'anumber'</span><span class="token3">,</span> <span class="token6">10</span><span class="token3">,</span> $success<span class="token3">)</span><span class="token3">,</span> PHP_EOL<span class="token3">;</span> ``` ``` - - - - - - **删** `apcu_delete( mixed $key ) : mixed -删除存储变量从缓存` ``` <pre class="calibre10">``` $bar <span class="token1">=</span> <span class="token2">'BAR'</span><span class="token3">;</span> <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">,</span> $bar<span class="token3">)</span><span class="token3">;</span> <span class="token4">apcu_delete</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">;</span> <span class="token">//删除多个</span> <span class="token4">apcu_delete</span><span class="token3">(</span><span class="token3">[</span><span class="token2">'foo'</span><span class="token3">,</span> <span class="token2">'bar'</span><span class="token3">,</span> <span class="token2">'baz'</span><span class="token3">]</span><span class="token3">)</span><span class="token3">;</span> ``` ``` `apcu_clear_cache() -清除APCu缓存 成功返回true` `apcu_enabled() — APCu在当前环境中是否可用 返回bool` `apcu_exists( mixed $keys ) : mixed -检查某个变量是否被缓存` ``` <pre class="calibre10">``` $fruit <span class="token1">=</span> <span class="token2">'apple'</span><span class="token3">;</span> <span class="token4">apcu_store</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">,</span> $fruit<span class="token3">)</span><span class="token3">;</span> <span class="token5">if</span> <span class="token3">(</span><span class="token4">apcu_exists</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">)</span> <span class="token3">{</span> echo <span class="token2">"Foo exists: "</span><span class="token3">;</span> echo <span class="token4">apcu_fetch</span><span class="token3">(</span><span class="token2">'foo'</span><span class="token3">)</span><span class="token3">;</span> <span class="token3">}</span> <span class="token5">else</span> <span class="token3">{</span> echo <span class="token2">"Foo does not exist"</span><span class="token3">;</span> <span class="token3">}</span> ``` ``` `apcu_entry( string $key , callable $generator [, int $ttl = 0 ] ) : mixed -自动读取或生成一个缓存条目` ``` <pre class="calibre10">``` $config <span class="token1">=</span> <span class="token4">apcu_entry</span><span class="token3">(</span><span class="token2">"config"</span><span class="token3">,</span> <span class="token5">function</span><span class="token3">(</span>$key<span class="token3">)</span> <span class="token3">{</span> <span class="token5">return</span> <span class="token3">[</span> <span class="token2">"fruit"</span> <span class="token1">=</span><span class="token1">></span> <span class="token4">apcu_entry</span><span class="token3">(</span><span class="token2">"config.fruit"</span><span class="token3">,</span> <span class="token5">function</span><span class="token3">(</span>$key<span class="token3">)</span><span class="token3">{</span> <span class="token5">return</span> <span class="token3">[</span> <span class="token2">"apples"</span><span class="token3">,</span> <span class="token2">"pears"</span> <span class="token3">]</span><span class="token3">;</span> <span class="token3">}</span><span class="token3">)</span><span class="token3">,</span> <span class="token2">"people"</span> <span class="token1">=</span><span class="token1">></span> <span class="token4">apcu_entry</span><span class="token3">(</span><span class="token2">"config.people"</span><span class="token3">,</span> <span class="token5">function</span><span class="token3">(</span>$key<span class="token3">)</span><span class="token3">{</span> <span class="token5">return</span> <span class="token3">[</span> <span class="token2">"bob"</span><span class="token3">,</span> <span class="token2">"joe"</span><span class="token3">,</span> <span class="token2">"niki"</span> <span class="token3">]</span><span class="token3">;</span> <span class="token3">}</span><span class="token3">)</span> <span class="token3">]</span><span class="token3">;</span> <span class="token3">}</span><span class="token3">)</span><span class="token3">;</span> <span class="token4">var_dump</span><span class="token3">(</span>$config<span class="token3">)</span><span class="token3">;</span> <span class="token">//以上例程会输出:</span> <span class="token4">array</span><span class="token3">(</span><span class="token6">2</span><span class="token3">)</span> <span class="token3">{</span> <span class="token3">[</span><span class="token2">"fruit"</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">array</span><span class="token3">(</span><span class="token6">2</span><span class="token3">)</span> <span class="token3">{</span> <span class="token3">[</span><span class="token6">0</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">string</span><span class="token3">(</span><span class="token6">6</span><span class="token3">)</span> <span class="token2">"apples"</span> <span class="token3">[</span><span class="token6">1</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">string</span><span class="token3">(</span><span class="token6">5</span><span class="token3">)</span> <span class="token2">"pears"</span> <span class="token3">}</span> <span class="token3">[</span><span class="token2">"people"</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">array</span><span class="token3">(</span><span class="token6">3</span><span class="token3">)</span> <span class="token3">{</span> <span class="token3">[</span><span class="token6">0</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">string</span><span class="token3">(</span><span class="token6">3</span><span class="token3">)</span> <span class="token2">"bob"</span> <span class="token3">[</span><span class="token6">1</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">string</span><span class="token3">(</span><span class="token6">3</span><span class="token3">)</span> <span class="token2">"joe"</span> <span class="token3">[</span><span class="token6">2</span><span class="token3">]</span><span class="token1">=</span><span class="token1">></span> <span class="token4">string</span><span class="token3">(</span><span class="token6">4</span><span class="token3">)</span> <span class="token2">"niki"</span> <span class="token3">}</span> <span class="token3">}</span> ``` ``` `apcu_sma_info([ bool $limited = FALSE ] ) : array -检索APCu共享内存分配信息` ``` <pre class="calibre10">``` <span class="token4">print_r</span><span class="token3">(</span><span class="token4">apcu_sma_info</span><span class="token3">(</span><span class="token3">)</span><span class="token3">)</span><span class="token3">;</span> <span class="token">//以上例程的输出类似于:</span> Array <span class="token3">(</span> <span class="token3">[</span>num_seg<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1</span> <span class="token3">[</span>seg_size<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">31457280</span> <span class="token3">[</span>avail_mem<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">31448408</span> <span class="token3">[</span>block_lists<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span> <span class="token3">[</span><span class="token6">0</span><span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span> <span class="token3">[</span><span class="token6">0</span><span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span> <span class="token3">[</span>size<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">31448408</span> <span class="token3">[</span>offset<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">8864</span> <span class="token3">)</span> <span class="token3">)</span> <span class="token3">)</span> <span class="token3">)</span> ``` ``` `apcu_cache_info([ bool $limited = FALSE ] ) -从APC的数据存储中检索缓存的信息和元数据` 如果limited为真,则返回值将排除缓存项的单个列表。这在尝试优化统计信息收集调用时非常有用 ``` <pre class="calibre10">``` <span class="token4">print_r</span><span class="token3">(</span><span class="token4">apcu_cache_info</span><span class="token3">(</span><span class="token3">)</span><span class="token3">)</span><span class="token3">;</span> 结果: Array <span class="token3">(</span> <span class="token3">[</span>num_slots<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">2000</span> <span class="token3">[</span>ttl<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">0</span> <span class="token3">[</span>num_hits<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">9</span> <span class="token3">[</span>num_misses<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">3</span> <span class="token3">[</span>start_time<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1123958803</span> <span class="token3">[</span>cache_list<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span> <span class="token3">[</span><span class="token6">0</span><span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span> <span class="token3">[</span>filename<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token1">/</span>path<span class="token1">/</span>to<span class="token1">/</span>apcu_test<span class="token3">.</span>php <span class="token3">[</span>device<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">29954</span> <span class="token3">[</span>inode<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1130511</span> <span class="token3">[</span>type<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> file <span class="token3">[</span>num_hits<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1</span> <span class="token3">[</span>mtime<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1123960686</span> <span class="token3">[</span>creation_time<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1123960696</span> <span class="token3">[</span>deletion_time<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">0</span> <span class="token3">[</span>access_time<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1123962864</span> <span class="token3">[</span>ref_count<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">1</span> <span class="token3">[</span>mem_size<span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> <span class="token6">677</span> <span class="token3">)</span> <span class="token3">[</span><span class="token6">1</span><span class="token3">]</span> <span class="token1">=</span><span class="token1">></span> Array <span class="token3">(</span><span class="token3">.</span><span class="token3">.</span><span class="token3">.</span>iterates <span class="token5">for</span> each cached file<span class="token3">)</span> <span class="token3">)</span> ``` ``` 注意:php-cli模式运行不能保存到下次运行(即命令行执行时,缓存无效) 在FastCGI模式下重启后将会清除缓存 ## **APCUIterator类** ``` <pre class="calibre17">``` APCUIterator implements <span class="token4">Iterator</span> <span class="token3">{</span> public __construct <span class="token3">(</span><span class="token3">[</span> mixed $search <span class="token1">=</span> NULL <span class="token3">[</span><span class="token3">,</span> int $format <span class="token1">=</span> APC_ITER_ALL <span class="token3">[</span><span class="token3">,</span> int $chunk_size <span class="token1">=</span> <span class="token6">100</span> <span class="token3">[</span><span class="token3">,</span> int $list <span class="token1">=</span> APC_LIST_ACTIVE <span class="token3">]</span><span class="token3">]</span><span class="token3">]</span><span class="token3">]</span> <span class="token3">)</span> public current <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> mixed <span class="token1">-</span> 得到当前项 public getTotalCount <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> int <span class="token1">-</span> 得到总数 public getTotalHits <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> int <span class="token1">-</span> 获取缓存总命中数 public getTotalSize <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> int <span class="token1">-</span> 获取总缓存大小 public key <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> string <span class="token1">-</span> 得到迭代器关键字 public next <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> bool <span class="token1">-</span> 移动指针到下一项 public rewind <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> void <span class="token1">-</span> 复原指针到初始位置 public valid <span class="token3">(</span> void <span class="token3">)</span> <span class="token3">:</span> bool <span class="token1">-</span> 检查当前位置是否有效 <span class="token3">}</span> ``` ```