PHP Velho Oeste 2024

APC 関数

目次

  • apc_add — 新規の変数をデータ領域にキャッシュする
  • apc_bin_dump — 指定したファイルおよびユーザー変数のバイナリダンプを取得する
  • apc_bin_dumpfile — キャッシュされたファイルやユーザー変数のバイナリダンプをファイルに出力する
  • apc_bin_load — バイナリダンプを APC のファイル/ユーザーキャッシュに読み込む
  • apc_bin_loadfile — バイナリダンプをファイルから APC のファイル/ユーザーキャッシュに読み込む
  • apc_cache_info — APC のデータから、キャッシュされた情報を取得する
  • apc_cas — 古い値を新しい値に更新する
  • apc_clear_cache — APC キャッシュをクリアする
  • apc_compile_file — ファイルをバイトコードキャッシュに保存し、すべてのフィルタをバイパスする
  • apc_dec — 保存した数値を減らす
  • apc_define_constants — 定数の組を定義し、それを取得あるいは一括定義する
  • apc_delete_file — ファイルを opcode キャッシュから削除する
  • apc_delete — 格納されている変数をキャッシュから取り除く
  • apc_exists — APC キーが存在するかどうかを調べる
  • apc_fetch — 格納されている変数をキャッシュから取得する
  • apc_inc — 保存した数値を増やす
  • apc_load_constants — 定数群をキャッシュから読み込む
  • apc_sma_info — APC の共有メモリ割り当てに関する情報を取得する
  • apc_store — 変数をデータ領域にキャッシュする
add a note add a note

User Contributed Notes 5 notes

up
7
zytzagoo at NOSPAMPLEASEgmail dot com
16 years ago
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.
up
3
joe at simpson dot com
16 years ago
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'
up
0
ashus at atlas dot cz
17 years ago
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.
up
0
dustymugs
17 years ago
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.
up
-2
bjoern dot andersen at atosorigin dot com
16 years ago
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.
To Top