am 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!!!