// load data with cache
function load_data($id,$cache_lifetime) {
// the return data
$data = array();
// make cache filename
$cache_filename = ‘cache_‘.$id.‘.php‘;
// check cache file‘s last modify time
$cache_filetime = filemtime($cache_filename);
if (time() - $cache_filetime <= $cache_lifetime) {
//** the cache is not expire
include($cache_filename);
} else {
//** the cache is expired
// load data from database
// ...
while ($dbo->nextRecord()) {
// $data[] = ...
}
// format the data as a php file
$data_cache = "
while (list($key, $val) = each($data)) {
$data_cache .= "$data[‘$key‘]=array(‘";
$data_cache .= "‘NAME‘=>"".qoute($val[‘NAME‘])."\","
$data_cache .= "‘VALUE‘=>\"".qoute($val[‘VALUE‘])."\""
$data_cache .= ";);\r\n";
}
$data_cache = "?>\r\n";
// save the data to the cache file
if ($fd = fopen($cache_filename,‘w+‘)) {
fputs($fd,$data_cache);
fclose($fd);
}
}
return $data;
}
?>
以上就介绍了2009nba总决赛数据 PHP数据缓存技术,包括了2009nba总决赛数据方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
已抢186747个
抢已抢67331个
抢已抢353248个
抢已抢667570个
抢已抢122772个
抢已抢24181个
抢