?
class="php" name="code">/**
* @Purpose: 设置缓存文件信息
* @Method Name:set_user_capacityCache()
* @Parameter: int $uid 用户的uid, array $arr 存放的数据数组
* @Return: 返回存放文件的字符长度
*/
function set_user_capacityCache($uid, $arr){
$objfile = get_user_capacityCache_path($uid);
$arrays = array();
if(file_exists($objfile)){
$arrays = include($objfile);
if(!is_array($arrays))
$arrays = array();
}
$arrays[$uid] = $arr;
$arrays = var_export($arrays,true);
$data = "<?php return ".$arrays."?>";
$strlen = file_put_contents($objfile, $data, LOCK_EX);
@chmod($objfile, 0777);
return $strlen;
}
/**
* @Purpose: 缓存文件存在 则取缓存的内容,不存在 返回false
* @Method Name:output_user_capacityCache()
* @Parameter: int $uid 用户的uid
* @Return: 存在 返回array数据 不存在 返回 false
*/
function output_user_capacityCache($uid)
{
$objfile = get_user_capacityCache_path($uid);
if(!file_exists($objfile))
{
return false;
}
else
{
$arrays = include($objfile);
if(!is_array($arrays) || empty($arrays[$uid]) || ($arrays[$uid]['timestamp'] + 24*3600 < time()))
return false;
return $arrays[$uid];
}
}
/**
* @Purpose: 取得能力集市信息文件路径
* @Method Name:??get_user_headCache_path()
* @Parameter: int $uid 用户的uid
* @Return: string 返回文件的路径
*/
function get_user_capacityCache_path($uid)
{
$dir = __DIR__;//目录
$folder_name = ceil($uid/10000); //文件夹名称
$file_name = ceil($uid/100).'.php'; //文件名称
$folder_dir = $dir.$folder_name."/";
$file_path = $folder_dir.$file_name;
if(!is_dir($folder_dir))
mkdir($folder_dir, 0777, true);
return $file_path;
}
?
?注意:只能存放数组,无法存放对象。