php 缓存技术实例_PHP教程

WBOY
Release: 2016-07-13 10:57:56
Original
1203 people have browsed it

php 缓存技术实例 本文章要讲的php 缓存技术是讲把数据生成一个临时缓存文件保存到硬盘,然后根据缓存文件设定的时间删除缓存文件再次生成新的缓存文件哦。

php教程 缓存技术实例
本文章要讲的php 缓存技术是讲把数据生成一个临时缓存文件保存到硬盘,然后根据缓存文件设定的时间删除缓存文件再次生成新的缓存文件哦。
*/

$filename = 'cachefile.php';
$str ='echo "bb";';
if( is_file( $filename ) )
{
$tmp = readcache( $filename ) ;
}
else
{
createcache( $filename,$str );
}

//写缓存文件

function createcache($filename,$str)
{
if( $str =='' ){ return false;}
$fp = fopen($filename,"w+") or die('缓存目录不可能,请设置/www.bKjia.c0m/cache为可写权限!');
if( ! fwrite($fp,$str) )
{
echo '不能创建缓存文件!';
exit;
}
fclose($fp);
}

//读取缓存文件

function readcache($filename)
{
$str = file_get_contents($filename);
if( $str == "" )
{
echo "缓存文件读取失败!";
exit;
}
return $str;
}

/*
本站原创文章,转载注明来源http://www.bKjia.c0m/phper/php.html
*/

www.bkjia.com true http://www.bkjia.com/PHPjc/632041.html TechArticle php 缓存技术实例本文章要讲的php 缓存技术是讲把数据生成一个临时缓存文件保存到硬盘,然后根据缓存文件设定的时间删除缓存文件再次生...
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!