window 环境安装 memcache 服务及简单测试

memcached.exe    下载 http://www.newasp.net/soft/63735.html#downloads
php_memcache.dll 下载 http://www.zhaodll.com/dll/p/201207/147016.html

windows 下安装 memcached.exe
1.把下载的文件解压到c盘,如:c:\memcached.exe
2.在终端(也即cmd命令界面)下输入 ‘c:\memcached.exe -d install’ 安装
3.再输入: ‘c:\memcached.exe -d start’ 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。
    这样服务器端已经安装完毕了。
4.下载php_memcache.dll,请自己查找对应的php版本的文件
5. 在php.ini 加入一行 ‘extension=php_memcache.dll’
6.重新启动Apache,然后查看一下phpinfo,如果有memcache,那么就说明安装成功!

memcached的基本设置:
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助


Memcache简单测试
<?php
$mem = new Memcache();
$mem->addserver("127.0.0.1", 11211);
$mem->set("mykey", "This is a test cache!", 0, 60);
$val = $mem->get("mykey");
echo $val;

$id=isset($_request['id'])?$_request['id']:1;

$sql="select prefix,main_name,cat_type from main_category where id=".$id;
$key=md5($sql);
if(!$mem->get($key)){
    
    echo 'this is mysql';
    echo "<br>";
    $data=array();
    $con=mysql_connect('127.0.0.1','root','');
    $db = mysql_select_db('center_app',$con);
    $result = mysql_query($sql);
    while($row=mysql_fetch_array($result)){
        $data[]=$row;
    }
    $mem->add($key,$data,0,60);
}else{
    $mem_data = $mem->get($key);
    echo 'this is memcache';
    echo "<br>";
    $data = $mem_data;
}
var_dump($data);
?>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值