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

WBOY
Release: 2016-06-13 12:55:05
Original
952 people have browsed it

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

<?php<br />
$file=file('link.txt');<br />
$max=count($file)-1;<br />
for($i=0;$i<5;$i++){<br />
	$index=mt_rand(0,$max);<br />
	$temp= "".trim($file["$index"])."";<br />
<br />
}<br />
$link = memcache_init();<br />
$minute_now = date('i',time());//取当前的分钟数<br />
$key = 'rate'.$minute_now;<br />
if(memcache_get($link,$key) == null)<br />
{<br />
        memcache_set($link, $key, $temp, 0, 20);//set<br />
        //注意此处的20是缓存过期时间,60秒为1分钟<br />
     <br />
}<br />
$re = memcache_get($link,$key,$temp);<br />
var_dump($re);<br />
if($re>RATEMAX)<br />
{<br />
<br />
}else{<br />
        memcache_increment($link,$key);<br />
}<br />
<br />
<br />
 ?>
Copy after login

没有缓存之前是每次刷新都是变的
缓存之后
演示地址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 相关的就是了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template