PHP 带缓存的简单下载页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 带缓存的简单下载页面相关的知识,希望对你有一定的参考价值。

function download($url, $cache_time=0)
{
	$cache_file = sys_get_temp_dir(). '/'. sha1($url);
	
	if (file_exists($cache_file) && (time() - @filemtime($cache_file) < $cache_time))
	{
		$file = file_get_contents($cache_file);
	} else {
		$file = file_get_contents($url);
		file_put_contents($cache_file, $file);
	}
	
	return $file;
}

以上是关于PHP 带缓存的简单下载页面的主要内容,如果未能解决你的问题,请参考以下文章

简单的PHP页面缓存技术

简单的PHP页面缓存技术

PHP 简单的页面缓存

PHP 简单的页面缓存

php静态缓存简单制作

php最基本的缓存之一页面缓存