标签:
2. 安装libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# cd libevent-1.4.6-stable
# ./configure --prefix=/usr/local/libevent
# make && make install
3. 安装memcached
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install
4. 运行memcached[红色的仔细看]
# /usr/local/memcached/bin/memcached -d -m 128 -l localhost -p 11211 -u root
如果遇到运行memcached时遇到问题,错误提示如下:
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
则运行 LD_DUBUG=libs 就可以知道memcached启动时库的加载路径。具体如下:
# LD_DEBUG=libs /usr/local/memcached/bin/memcached -v
然后给libevent-1.4.so.2建立一个链接后再运行memcached:
# ln -s /usr/local/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
5.安装PHP的memcache
PHP环境下使用memcached:可以使用php自带的pecl安装程序
# /usr/local/php5/bin/pecl install memcache
返回:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
表示成功安装!
6.检查服务
(1)查看启动的memcache服务:
netstat -lp | grep memcached
(2)查看memcache的进程号(根据进程号,可以结束memcache服务:“kill -9 进程号”)
ps -ef | grep memcached
将memcache扩展加入到php.ini
extension=memcache.so
测试:
phpinfo();
程序测试:
<?php
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect(‘localhost‘, 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set(‘key‘, ‘test‘); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get(‘key‘); //从内存中取出key的值
echo $get_value;
?>
标签:
原文地址:http://www.cnblogs.com/zxm0125/p/4402026.html