文字

APC 函数

Table of Contents

  • apc_add — 缓存一个变量到数据存储
  • apc_bin_dump — Get a binary dump of the given files and user variables
  • apc_bin_dumpfile — Output a binary dump of cached files and user variables to a file
  • apc_bin_load — Load a binary dump into the APC file/user cache
  • apc_bin_loadfile — Load a binary dump from a file into the APC file/user cache
  • apc_cache_info — Retrieves cached information from APC's data store
  • apc_cas — 用新值更新旧值
  • apc_clear_cache — 清除APC缓存
  • apc_compile_file — Stores a file in the bytecode cache, bypassing all filters.
  • apc_dec — Decrease a stored number
  • apc_define_constants — Defines a set of constants for retrieval and mass-definition
  • apc_delete_file — Deletes files from the opcode cache
  • apc_delete — 从用户缓存中删除某个变量
  • apc_exists — 检查APC中是否存在某个或者某些key
  • apc_fetch — 从缓存中取出存储的变量
  • apc_inc — 递增一个储存的数字
  • apc_load_constants — Loads a set of constants from the cache
  • apc_sma_info — Retrieves APC's Shared Memory Allocation information
  • apc_store — Cache a variable in the data store

用户评论:

[#1] joe at simpson dot com [2007-09-20 04:53:38]

It seems there are issues when using APC to cache database result sets as PDOStatements. Any attempts I have made always result in an exception being thrown with the message: 'You cannot serialize or unserialize PDOStatement instances'

[#2] zytzagoo at NOSPAMPLEASEgmail dot com [2007-07-30 06:21:49]

Keep in mind to always prefix or suffix your cache key names with something specific to your site/app/setup, to avoid the risk of your apc cache entries being overwritten/deleted/modified by someone else on the same server.

Assume we have some code like this:

<?php apc_store('config'$cfg); ?>

Now assume someone else on the same server is also using 'config' as the key passed to an apc_store(), apc_delete() (etc.) call in some other piece of code on the whole server.

Since you're both working on the exact same cache entry, all sorts of wierd things can happen, but the problem is not in your code at all.

[#3] bjoern dot andersen at atosorigin dot com [2007-05-23 08:14:38]

In IIS6 you can't use php_apc.dll with application pools or webgardens (Multi-Instance/Multi-Threading). Maybe this applies even to all Multithreading environments - i don't know. 

When you try it, the Application pools terminate when requests run simultaneously.

[#4] ashus at atlas dot cz [2007-03-21 06:56:47]

If you don't really need caching and plan to use it for one page only, you could try an alternative; writing a file and then flushing it back if specified time hasn't passed. I use it to read and parse third party websites, to check for new subtitles and output a RSS xml file.

<?php
if ((is_file($_SERVER['SCRIPT_FILENAME'].'.cached'))
    && (
time()-filemtime($_SERVER['SCRIPT_FILENAME'].'.cached') < 3600))
    {
    
readfile($_SERVER['SCRIPT_FILENAME'].'.cached');
    exit;
    }

// (the php script itself goes here)

echo $out;
$fp fopen($_SERVER['SCRIPT_FILENAME'].'.cached''w');
fwrite($fp$out);
fclose($fp);

?>


Note, that this only works for pages, which are without GET or POST variables, sessions, etc. You can change the number of seconds the cache works for (3600 = an hour). Also, use "$out.=" instead of "echo" command. Just store all output to that variable (if you need to use it inside a function, use "global $out" instead).
This workaround was written in about 5 minutes and may contain bugs.

[#5] dustymugs [2007-01-30 18:14:55]

In windows, if you load php_apc.dll but do not enable it, apache may crash when attempting to restart or stop.

So, if you've not enabled APC but are loading it, comment out the loading.

上一篇: 下一篇: