教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 缓存技术实例

php 缓存技术实例

发布时间:2016-12-04   编辑:jiaochengji.com
教程集为您提供php 缓存技术实例等资源,欢迎您收藏本站,我们将为您提供最新的php 缓存技术实例资源
本文章要讲的php 缓存技术是讲把数据生成一个临时缓存文件保存到硬盘,然后根据缓存文件设定的时间删除缓存文件再次生成新的缓存文件哦。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9834')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9834>

$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.jiaochengji.com/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.jiaochengji.com/phper/php.html
*/

您可能感兴趣的文章:
php后端开发主要会哪些技术
php页面缓存的例子(减经cpu与mysql负担)
php简单页面缓存的实现代码
php 缓存技术实例
php后端开发要学什么
有关php的缓存技术介绍
PHP中常用三种缓存技术
CodeIgniter框架中启用和清除缓存的教程
php输出缓存ob系列函数用法
PHP输出缓冲及其应用的例子

[关闭]
~ ~