Home > php教程 > PHP源码 > PHP 动态网站变 静态缓存 加快网站访问速度

PHP 动态网站变 静态缓存 加快网站访问速度

PHP中文网
Release: 2016-05-25 17:07:32
Original
1135 people have browsed it

<?php
if($_GET[&#39;phphuancun&#39;]!="true"){
define("HC_PATH",dirname(__FILE__)."/cache/");
define("HC_TIME",1);
echo HC_getcache();exit;
}
function HC_getcache($iscache=&#39;&#39;)
{
	$url="http://".$_SERVER[&#39;SERVER_NAME&#39;].$_SERVER[&#39;REQUEST_URI&#39;];
	$cacheurl=strpos($url,"?")?$url."&phphuancun=true":$url."?phphuancun=true";
	$cachename=HC_PATH.md5($url).".c";

	$cachetime=$iscache?time()+1:time()-(HC_TIME * 60*60);
	if(file_exists($cachename) && filemtime($cachename)>=$cachetime){
		$return=file_get_contents($cachename);$data=function_exists(gzcompress)?@gzuncompress($return):$return;
		return unserialize($data);
	}else{$return=file_get_contents($cacheurl);HC_writecache($cachename,$return);return $return;}

}
function HC_writecache($name,$array)
{
	function_exists(gzcompress)?$return =gzcompress(serialize($array)):$return=serialize($array);
	@file_put_contents($name,$return);
}
?>
Copy after login

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