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

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

PHP中文网
PHP中文网Original
2016-05-25 17:11:591039browse

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, "读取栏目缓存文件失败");
	}
}

                   

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

Statement:
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