免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2652 | 回复: 5
打印 上一主题 下一主题

[缓存] 一个最最最简单的eAccelerator缓冲计数器 [复制链接]

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-06 16:52 |只看该作者 |倒序浏览
[缓存] 一个最最最简单的eAccelerator缓冲计数器

简单说明:把他理解为一个最最最简单的数据库,其只能使用索引来操作值:

函数说明:
查询值:eaccelerator_get(string $key) 没有结果返回NULL
更新值:eaccelerator_put(string $key, mixed $needle, int $ttl);
删除值:eaccelerator_rm(string $key);

计数器说明:
每$intUpdateBase次计数才更新到记录文件(你可以操作到数据库)



  1. <?php
  2. $strCountKey = 'count_key';
  3. $intUpdateBase = 100;

  4. $intCount = eaccelerator_get("$strCountKey");
  5. if(!$intCount || $intCount<1){
  6.         if(file_exists(dirname(__FILE__)."/$strCountKey.log")){
  7.                 $strCount = file_get_contents(dirname(__FILE__)."/$strCountKey.log");
  8.                 $strCount = trim($strCount);
  9.                 $intCount = intval($strCount);
  10.         }
  11.         if(!$intCount || $intCount<1){
  12.                 $intCount = 0;
  13.         }
  14. }
  15. eaccelerator_put("$strCountKey", ++$intCount, 86400);
  16. echo($intCount);
  17. if($intCount%$intUpdateBase==0){
  18.         $fp = fopen(dirname(__FILE__)."/$strCountKey.log",'w');
  19.         fputs($fp,$intCount);
  20.         fclose($fp);
  21. }
  22. /// eaccelerator_rm("$strCountKey");
  23. exit;
  24. ?>
复制代码

论坛徽章:
0
2 [报告]
发表于 2006-06-07 15:26 |只看该作者
晕,需要这么麻烦吗?

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
3 [报告]
发表于 2006-06-07 21:55 |只看该作者
原帖由 ashchen 于 2006-6-7 15:26 发表
晕,需要这么麻烦吗?


这个只是一个演示。
而且如果停止了,或者重启了,计数值的误差只在100以内,会自动回复到上一次的。

论坛徽章:
0
4 [报告]
发表于 2006-06-08 01:09 |只看该作者
计数什么的?访问量?

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
5 [报告]
发表于 2006-06-08 08:34 |只看该作者
这个看你自己的选择了,爱做就做

论坛徽章:
0
6 [报告]
发表于 2006-06-08 08:59 |只看该作者
学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP