1.系统自带libevent1.1
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 Mar 13 20:57 libevent-1.1.so.1 -> libevent-1.1.so.1.0.2
-rwxr-xr-x 1 root root 28588 Jun 16 2006 libevent-1.1.so.1.0.2
-rw-r–r– 1 root root 35264 Jun 16 2006 libevent.a
-rw-r–r– 1 root root 805 Jun 16 2006 libevent.la
lrwxrwxrwx 1 root root 21 Mar 13 20:57 libevent.so -> libevent-1.1.so.1.0.2
2.安装memcache
# cd /tmp
# wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
# tar zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure –with-libevent=/usr
# make
# make install
查看安装情况:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 202219 Apr 13 09:55 /usr/local/bin/memcached
启动一个Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.4.170 -p 11211 -c 256 -P /tmp/memcached.pid
如果是监(和谐)听全部IP可以用0.0.0.0代替IP
3.安装Memcache的PHP扩展
# cd /tmp
# wget http://pecl.php.net/get/memcache-2.2.5.tgz
# tar zxvf memcache-2.2.5.tgz
# cd memcache-2.2.5/
# phpize
./configure –with-php-config=/usr/bin/php-config -enable-memcache -with-zlib-dir –disable-memcache-session
# make
# make install
添加memcache.so到php.ini的extendions
# cd /etc/php5/conf.d/
# vi memchache.ini
输入:
extension=memcache.so
保存退出,重启apache
<?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;
?>