摘要:由于数据库存储的数据量越来越大,查询速度也就变的越来越慢,因此就有了缓存服务器应用的必要,本文是介绍Memcached的安装以及简单的使用。
本文只介绍memcached的PHP的API,想查看其他关于Memcached的API文档案,请访问 http://www.danga.com/memcached/
目录
++++++++++++++++++++++++++++++++++++++++
正文
++++++++++++++++++++++++++++++++++++++++
一、环境需求
安装Memcached需要libevent库的支持,所以请在安装Memcached之前检查有没有安装libevent。测试环境还需要PHP的支持,本文假设PHP已经安装到/usr/local/PHP目录下,也就是在编译PHP的时候使用perfix参数指定目录(--prefix=/usr/local/PHP)
二、下载相关软件
Memcached下载地址:http://www.danga.com/memcached/
memcache PHP模块下载地址: http://pecl.PHP.net/package/memcache 推荐使用1.5版
libevent 下载地址: http://www.monkey.org/~provos/libevent/
本文不再讲述如何安装libevent
三、安装和配置
1、安装Memcached
root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install
安装完之后要启动服务
root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root
参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行
2、安装memcache PHP模块
root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/PHP/bin/PHPize
root@tonyvicky:# ./configure --enable-memcache --with-PHP-config=/usr/local/PHP/bin/PHP-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/PHP/bin/PHPize
root@tonyvicky:# ./configure --enable-memcache --with-PHP-config=/usr/local/PHP/bin/PHP-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install
安装完后会有类似这样的提示:
extension_dir = "./"
修改为
并添加一行
extension=memcache.so
自己写一个PHP程序测试一下吧
PHP
$memcache 名称是key 值是test
$memcache 名称是key 值是test