Home > php教程 > PHP源码 > MyNews 调用栏目信息(缓存方式)

MyNews 调用栏目信息(缓存方式)

PHP中文网
Release: 2016-05-25 17:11:59
Original
1063 people have browsed it

MyNews 调用栏目信息(缓存方式)

function getCategorys () {
	global $mysql, $cfg_cache_category;
	$cache = SYSPATH . "/data/cache/categorys.php";
	if (!file_exists($cache) || (time() - filemtime($cache)) > $cfg_cache_category) {
		$categorys = array();
		$arrays = $mysql->getArrays("SELECT id, fid, name, url FROM my_category");
		if (!empty($arrays)) {
			foreach ($arrays as $v) {
				$categorys[$v['id']] = $v;
			}
			unset($arrays);
			unset($v);
		}
		$fp = fopen($cache, 'w');
		if ($fp) {
			fwrite($fp, serialize($categorys));
			fclose($fp);
		} else {
			httpError(500, "写入栏目缓存文件失败");
		}
		unset($categorys);
	}
	$fp = fopen($cache, 'r');
	if ($fp) {
		$array = unserialize(fread($fp, filesize($cache)));
		return $array;
		unset($array);
	} else {
		httpError(500, "读取栏目缓存文件失败");
	}
}
Copy after login

                   

 以上就是MyNews 调用栏目信息(缓存方式)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template