windows下安装和使用memcached

来源:互联网 发布:mac联网恢复系统要多久 编辑:程序博客网 时间:2024/05/20 08:27

memcached 是高效、快速的分布式内存对象缓存系统,主要用于加速 WEB 动态应用程序
Php memcached官方手册地址:http://cn2.php.net/manual/en/memcached.get.php
1. 下载memcached
从 http://code.jellycan.com/files/ 下载windows下可执行版本的memcached,我下载的是memcached-1.2.6-win32-bin.zip
从 http://downloads.php.net/pierre/ 下载php_memcache.dll
php_memcache.dll的版本需要与php版本一致
2. 安装memcached
将下载的memcached解压,cmd进入memcached.exe目录
memcached.exe -d install:安装memcached服务
memcached.exe -d start:启动memcached服务
验证: 在进程管理器中能看到memcached进程
在cmd下输入"netstat -ano|findstr 11211",能看到memcached监听
3. 安装php_memcache模块
将下载的php_memcache.dll放到php/ext目录下
修改php.ini,加入"extension=php_memcache.dll"语句
重启apache
查看phpinfo(),已经开启了memcache模块
4. 使用memcached
http://www.cnblogs.com/czh-liyu/archive/2010/04/27/1722084.html
常用命令有set add replace get delete stats flush_all
command <key> <flags> <expiration time> <bytes>
<value>


php中使用memcached
$memcache_obj = new Memcache;
$memcache_obj->connect('localhost', 11211); 
$memcache_obj->set('var_key', 'This is a memcached test!',MEMCACHE_COMPRESSED, 50);
echo $memcache_obj->get('var_key');