memcache模拟
来源:互联网 发布:淘宝 clarks小公主 编辑:程序博客网 时间:2024/05/21 09:36
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <script src="jquery-2.1.1.min.js"></script></head><body><center> <table> <tr> <td>用户名:</td> <td><input type="text"/></td> </tr> <tr> <td>手机号码:</td> <td><input type="text" id="tel"/><span></span></td> </tr> <tr> <td><button>查询</button></td> </tr> </table></center></body></html><script>$(function(){ $("button").click(function(){ var obj=$(this); var tel=$("#tel").val(); var url='http://www.lijian.com/m9/d919a/index.php?tel='+tel; $.get(url,function(msg){ //alert(msg)// var str='';// for(var i= 0;i<msg.length;i++){// str+='<span>'+msg[i].name+'</span>'// } $("span").html(msg); },'json') })})</script><?php/** * Created by PhpStorm. * User: Administrator * Date: 2016/9/20 * Time: 9:28 */header("content-type:text/html;charset=utf-8");//$pdo=new PDO('mysql:host=localhost;dbname=test','root','root');//$pdo->exec("set names utf8");//开启缓存$mem=new Memcache();$mem->connect("127.0.0.1",11211);//清除缓存//$mem->flush();die;$tel=$_GET['tel'];//从缓存取出被查询了的次数$num=$mem->get($tel);set_time_limit(0);$url = "http://api.k780.com:88/?app=phone.get&phone=".$tel."&appkey=20900&sign=b07840f44dc8e8c7b08dd44b12032338&format=json";if($num){//已存在 //每一次加一 $num++; $mem->set($tel,$num); //再判断次数 if($num>5){ //大于五次取memcache数据 $str=$mem->get('data'.$tel); echo $str; }elseif( //第五次取出的数据放到memcache $num==5 ){// $data=$pdo->query("select * from tel WHERE tel='$tel'")->fetchAll(PDO::FETCH_ASSOC);// $str=json_encode($data);// $mem->set('data'.$tel,$str);// echo $str; $str = file_get_contents($url); $data = json_decode($str,true); $operators = $data['result']['operators']; echo json_encode($operators); }else{ //直接查输出// $data=$pdo->query("select * from tel WHERE tel='$tel'")->fetchAll(PDO::FETCH_ASSOC);// $str=json_encode($data);// echo $str; $str = file_get_contents($url); $data = json_decode($str,true); $operators = $data['result']['operators']; echo json_encode($operators); }}else{ //第一次访问 $mem->set($tel,1);// $data=$pdo->query("select * from tel WHERE tel='$tel'")->fetchAll(PDO::FETCH_ASSOC);// echo json_encode($data); $str = file_get_contents($url); $data = json_decode($str,true); $operators = $data['result']['operators']; echo json_encode($operators);}
0 0
- memcache模拟
- Memcache 中模拟 namespace
- memcache+cookie 模拟 Session
- Memcache+cookie实现模拟session
- Memcache
- MemCache
- Memcache
- Memcache
- Memcache
- memcache
- Memcache
- Memcache
- memcache
- memcache
- memcache
- memcache
- Memcache
- MemCache
- 开始写博客
- Linux文件读写机制及优化方式
- 网络编程(11)—— 进程和僵尸进程
- 【Spring学习笔记】文件上传
- Repeater 双向排序
- memcache模拟
- 自学MVC看这里——全网最全ASP.NET MVC 教程汇总
- 飞思卡尔IMX6处理器的GPIO配置方式
- Oracle 10g的安装步骤和注意事项
- 海思移植opencv+人脸检测+速度优化
- Java中List、Set、Map区别--小记
- Linux中read接收用户输入
- 把在程序中的System.out.print()的信息自动转成log4j日志信息
- JavaScript 读取XML文件进行广告播放