PHP APC的安装与使用详解(2)

三、PHP_APC函数
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— Updates an old value with a new value
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

四、PHPAPC使用
使用apc缓存的示例(test_apc_cache.php):

复制代码 代码如下:


<?php
error_reporting(E_ALL);
classapcInit {
/**
*Apc缓存-设置缓存
*设置缓存key,value和缓存时间
*@param string $key KEY值
*@param string $value值
*@param string $time缓存时间
*/
publicstatic function set_cache($key, $value, $time = 0) {
if($time == 0) $time = null; //null情况下永久缓存
returnapc_store($key, $value, $time);;
}
/**
*Apc缓存-获取缓存
*通过KEY获取缓存数据
*@param string $key KEY值
*/
publicstatic function get_cache($key) {
returnapc_fetch($key);
}
/**
*Apc缓存-清除一个缓存
*从memcache中删除一条缓存
*@param string $key KEY值
*/
publicstatic function clear($key) {
returnapc_delete($key);
}
/**
*Apc缓存-清空所有缓存
*不建议使用该功能
*@return
*/
publicstatic function clear_all() {
returnapc_clear_cache(); //清楚缓存
}
/**
*检查APC缓存是否存在
*@param string $key KEY值
*/
publicstatic function exists($key) {
returnapc_exists($key);
}
/**
*字段自增-用于记数
*@param string $key KEY值
*@param int $step新增的step值
*/
publicstatic function inc($key, $step) {
returnapc_inc($key, (int) $step);
}
/**
*字段自减-用于记数
*@param string $key KEY值
*@param int $step新增的step值
*/
publicstatic function dec($key, $step) {
returnapc_dec($key, (int) $step);
}
/**
*缓存文件
*/
publicstatic function cache_file($file) {
returnapc_compile_file($file);
}
/**
*返回APC缓存信息
*/
publicstatic function info() {
returnapc_cache_info();
}
}
apc_clear_cache();
apcInit::cache_file("HessianUtils.php");
apcInit::cache_file("Hessian1Parser.php");
apcInit::cache_file("Hessian1Writer.php");
apcInit::cache_file("HessianStream.php");
apcInit::cache_file("HessianParsing.php");
apcInit::cache_file("HessianExceptions.php");
include_once"./HessianUtils.php";
include_once"./Hessian1Parser.php";
include_once"./Hessian1Writer.php";
include_once"./HessianStream.php";
include_once"./HessianParsing.php";
include_once"./HessianExceptions.php";
header("Content-type:text/html;charset=utf-8");
header("Cache-Control:private,max-age=0,no-cache");
$HessianWriter= new Hessian1Writer();
$array= array(1, 2, 3, array('sff','张三'));
//parser
$resolver= new HessianRuleResolver('./hessian1rules.php');
//解析array
$parser_array= new Hessian1Parser($resolver, newHessianStream($HessianWriter->writeValue($array)));
print_r($parser_array->parse());
?>


五、PHPAPC监控与管理
APC提供了apc.php,用于监控与管理APC缓存。将apc.php放到网站目录中,修改账号、密码,即可通过浏览器监控与管理APC缓存。
apc.php第41、42行:

复制代码 代码如下:


defaults('ADMIN_USERNAME','apc');// Admin Username
defaults('ADMIN_PASSWORD','password'); // Admin Password - CHANGE THIS TO ENABLE!!!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e0ddfd46dde8f89d5571885fda45cdee.html