三、安装
1、安装libevent
root@wxlccsu:# tar vxzf libevent-2.0.9-rc.tar.gz
root@wxlccsu:# cd libevent-2.0.9
root@wxlccsu:# ./configure
root@wxlccsu:# make
root@wxlccsu:# make install
2、安装Memcached
root@wxlccsu:# tar vxzf memcached-1.4.5.tar.gz
root@wxlccsu:# cd memcached-1.4.5
root@wxlccsu:# ./configure --prefix=/usr/local/memcached
root@wxlccsu:# make
root@wxlccsu:# make install
安装完之后要启动服务
root@wxlccsu:# cd /usr/local/memcached/bin
root@wxlccsu:# ./memcached -d -m 50 -p 11211 -u root
启动memcached出现状况
error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
在网上查了下
解决这个问题有如下方法:
1>首先 find / -name libevent-2.0.so.5 找到缺少的链接文件到底在那儿。
2> LD_DEBUG=libs /usr/local/memcached/bin/memcached -v
3> 从Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib/libevent-2.0.so.5 而我的链接库的实际存储位置是 /usr/local/lib/libevent-2.0.so.5
4>做一个软连接 ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.
5>搞定.
<?php
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'this is a test by wxlccsu !'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;
phpinfo();
?>
通过浏览器查看此页面可以看到:this is a test by wxlccsu !
并且在php模块信息中可以看到memcache的相关信息。