首页 > 开发 > PHP > 正文

php 缓存设计

2024-05-04 21:56:28
字体:
来源:转载
供稿:网友
  1. <?php 
  2. //本功能主要是利用文件修改时间函数filemtime与现在时间作减法判断是否更新内容。 
  3. $cahetime=2;//设置过期时间 
  4. $cahefile="cahe.txt";//读写文本 
  5. if(file_exists($cahefile) && time()-$cahetimefilemtime($cahefile)){ 
  6.   
  7.   echo file_get_contents($cahefile); 
  8.  } 
  9.  else { 
  10.   file_put_contents($cahefile,date("y-m-d H:i:s",time())); 
  11.  } 
  12. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表