PHP头条
热点:

php怎么根据url参数缓存到memcache


php如何根据url参数缓存到memcache?

$file=file('link.txt');
$max=count($file)-1;
for($i=0;$i<5;$i++){
$index=mt_rand(0,$max);
$temp= "".trim($file["$index"])."";

}
$link = memcache_init();
$minute_now = date('i',time());//取当前的分钟数
$key = 'rate'.$minute_now;
if(memcache_get($link,$key) == null)
{
        memcache_set($link, $key, $temp, 0, 20);//set
        //注意此处的20是缓存过期时间,60秒为1分钟
     
}
$re = memcache_get($link,$key,$temp);
var_dump($re);
if($re>RATEMAX)
{

}else{
        memcache_increment($link,$key);
}


 ?>

没有缓存之前是每次刷新都是变的
缓存之后
演示地址http://niaochen006.sinaapp.com/zq.php
缓存时间 20秒变一次

我想要实现的是 
http://niaochen006.sinaapp.com/zq.php?=AABB
http://niaochen006.sinaapp.com/zq.php?=BBCC
http://niaochen006.sinaapp.com/zq.php?=*****

每个URL参数不同就缓存不同的页面
如何实现呢?
------解决方案--------------------
改造一下 $key 
你现在的
$key = 'rate'.$minute_now;
是与时间相联系的

改成与 $url 相关的就是了

www.phpzy.comtrue/phprm/15052.htmlTechArticlephp怎么根据url参数缓存到memcache php如何根据url参数缓存到memcache? $file=file('link.txt'); $max=count($file)-1; for($i=0;$i $index=mt_rand(0,$max); $temp="".trim($file["$index"]).""; } $link=memcache_init(); $minute_now=...

相关文章

相关频道:

PHP之友评论

今天推荐