- 论坛徽章:
- 1
|
[缓存] 一个最最最简单的eAccelerator缓冲计数器
简单说明:把他理解为一个最最最简单的数据库,其只能使用索引来操作值:
函数说明:
查询值:eaccelerator_get(string $key) 没有结果返回NULL
更新值:eaccelerator_put(string $key, mixed $needle, int $ttl);
删除值:eaccelerator_rm(string $key);
计数器说明:
每$intUpdateBase次计数才更新到记录文件(你可以操作到数据库)
- <?php
- $strCountKey = 'count_key';
- $intUpdateBase = 100;
- $intCount = eaccelerator_get("$strCountKey");
- if(!$intCount || $intCount<1){
- if(file_exists(dirname(__FILE__)."/$strCountKey.log")){
- $strCount = file_get_contents(dirname(__FILE__)."/$strCountKey.log");
- $strCount = trim($strCount);
- $intCount = intval($strCount);
- }
- if(!$intCount || $intCount<1){
- $intCount = 0;
- }
- }
- eaccelerator_put("$strCountKey", ++$intCount, 86400);
- echo($intCount);
- if($intCount%$intUpdateBase==0){
- $fp = fopen(dirname(__FILE__)."/$strCountKey.log",'w');
- fputs($fp,$intCount);
- fclose($fp);
- }
- /// eaccelerator_rm("$strCountKey");
- exit;
- ?>
复制代码
|
|