memcache和memcached安装

来源:互联网 发布:淘宝泰国代购哪家好 编辑:程序博客网 时间:2024/05/23 16:37

首先要明确  memcache不是memcached

 

第一步安装libevent

#wget  https://github.com/downloads/libevent/libevent/libevent-2.0.15-stable.tar.gz

#tar libevent-2.0.15-stable.tar.gz

#tar xzvf libevent-2.0.15-stable.tar.gz

#cd libevent-2.0.15-stable

#./configure --help

#whereis libevent

#./configure --prefix=/usr

#ls -al /usr/lib|grep libevent

#make

#make install

#ls -al /usr/lib|grep libevent

#ldconfig -v

#ldconfig

-------------------------------------------------------------------------------------------- 

 

第二步安装memcached

# wget http://memcached.googlecode.com/files/memcached-1.4.9.tar.gz

#tar xzvf memcached-1.4.9.tar.gz

#cd memcached-1.4.9

#./configure --help

#./configure --prefix=/usr/local/memcached --with-libevent=/usr

#make

#make install

#ls /usr/local/memcached/bin/memcached -lh

#netstat –ntlpu

#/usr/local/memcached/bin/memcached -d -m 100 -uroot -l 0.0.0.0 -p 11211 -c 512 -P /usr/local/memcached/memcached.pid

#netstat -ntlpu

-------------------------------------------------------------------------

memcached进程的查看与结束

#ps aux|grep mem

#cat /usr/local/memcached/memcached.pid

#ps aux 也可以查进程

杀死memcached进程

#kill   进程id

---------------------------------------------------------------------------------

 

第三步 安装php的memcached扩展memcache

#wget http://pecl.php.net/get/memcache-2.2.6.tgz

#tar vxzf memcache-2.2.6.tgz

#cd memcache-2.2.6

#/usr/local/php/bin/phpize

#./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir

或者

#./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir=/usr

#make

#make install

 

/usr/local/php/lib/php.ini

php.ini添加

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

;extension=memcache.so

如果程序没有dl("memcache.so");是要这里加的。

 

-----------------------------------------------------------------------

测试

Memcache环境测试
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?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;
?>