Memcache是一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的Hash表,能够用来存储各种格式的数据。
1: 还是下载
Memcache是用C编写的,要用到C的libevent来处理接口
点击下载memcached-1.4.0.tar.gz:http://www.danga.com/memcached/dist/memcached-1.4.0.tar.gz
下载libevent-2.0.13-stable.tar.gz:http://www.monkey.org/~provos/libevent-2.0.13-stable.tar.gz
下载memcache-3.0.6.tgz:http://pecl.php.net/get/memcache-3.0.6.tgz
我下载到了/root/Downloads
2:解压编译
a:先安装libevent
#cd /Downloads
#tar zvxf libevent-2.0.13-stable.tar.gz
#cd libevent-2.0.13-stable
#./configure --prefix=/usr
#make
#make install
查看下安装是否成功
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 2011-03-30 11:03 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
-rw-r--r-- 1 root root91768 2009-12-06 05:52 libevent-1.4.so.2.1.3
lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent-2.0.so.5 -> libevent-2.0.so.5.1.2
-rwxr-xr-x 1 root root 817306 2011-09-16 01:41 libevent-2.0.so.5.1.2
-rw-r--r-- 1 root root 1048354 2011-09-16 01:41 libevent.a
lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.2
-rwxr-xr-x 1 root root 499865 2011-09-16 01:41 libevent_core-2.0.so.5.1.2
-rw-r--r-- 1 root root 657028 2011-09-16 01:41 libevent_core.a
-rwxr-xr-x 1 root root 968 2011-09-16 01:41 libevent_core.la
lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core.so -> libevent_core-2.0.so.5.1.2
lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.2
-rwxr-xr-x 1 root root 335387 2011-09-16 01:41 libevent_extra-2.0.so.5.1.2
-rw-r--r-- 1 root root 391398 2011-09-16 01:41 libevent_extra.a
-rwxr-xr-x 1 root root 975 2011-09-16 01:41 libevent_extra.la
lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra.so -> libevent_extra-2.0.so.5.1.2
-rwxr-xr-x 1 root root 933 2011-09-16 01:41 libevent.la
lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.2
-rwxr-xr-x 1 root root80238 2011-09-16 01:41 libevent_openssl-2.0.so.5.1.2
-rw-r--r-- 1 root root86344 2011-09-16 01:41 libevent_openssl.a
-rwxr-xr-x 1 root root 1004 2011-09-16 01:41 libevent_openssl.la
lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.2
lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.2
-rwxr-xr-x 1 root root15733 2011-09-16 01:41 libevent_pthreads-2.0.so.5.1.2
-rw-r--r-- 1 root root12998 2011-09-16 01:41 libevent_pthreads.a
-rwxr-xr-x 1 root root 996 2011-09-16 01:41 libevent_pthreads.la
lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.2
lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent.so -> libevent-2.0.so.5.1.2
b. 安装memcached
#cd ..
#tar zxvf memcached-1.4.0.tar.gz
#cd memcached-1.4.0
# ./configure –with-libevent=/usr
# make
# make install
c. 安装memcache
#cd ..
#tar vxzf memcache-3.0.6.tgz
#cd memcache-3.0.6
#/usr/local/php/bin/phpize
#./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
#make
#make install
#gvim /etc/php5/apache2/php.ini
修改php.ini中的extension_dir = “./”
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
添加
extension=memcache.so
3: 启动和关闭
#/usr/local/bin/memcached -d -m 128 -u root -l 127.0.0.1 -p 11211 -c 256 -P /var/temp/memcached.pid
#kill `cat /var/temp/memcached.pid` 或者#killall memcached
重启apache
sudo /etc/init.d/apche2 restart
4:测试
< ?php
$mem = new Memcache;
$mem->connect(“127.0.0.1″, 11211);
$mem->set(‘key’, ‘This is a test!’, 0, 60);
$val = $mem->get(‘key’);
echo $val;
?>
5: Ubuntu/debian 。
直接sudo
sudo apt-get install memcached
启动
memcached -d -m 128 -p 11211 -u root -l 127.0.0.1
太轻松了。