一、memcached 的编译安装
准备:
Memcached下载地址:http://www.danga.com/memcached/
libevent下载地址: http://monkey.org/~provos/libevent/
安装步骤:
1. 下载libevent & memcached 源码包
libevent-1.3.tar.gz
memcached-1.2.2.tar.gz
memcached-1.2.2.tar.gz
2. 解压缩 libevent-1.3.tar.gz ,编译安装
# tar zxvf libevent-1.3.tar.gz
# cd libevent-1.3
# ./configure --prefix=/usr/local/libevent
# make ; make install
# cd libevent-1.3
# ./configure --prefix=/usr/local/libevent
# make ; make install
3. 解压缩 memcached-1.2.2.tar.gz, 编译安装
# tar zxvf memcached-1.2.2.tar.gz
# cd memcached-1.2.2
# ./configure --prefix=/usr/local/memchached --with-libevent=/usr/local/libevent
# make;make install
# cd memcached-1.2.2
# ./configure --prefix=/usr/local/memchached --with-libevent=/usr/local/libevent
# make;make install
4. 作软连接,否则运行memcached的时候将找不到libevent模块
# ln -s /usr/local/libevent/lib/libevent-1.3.so.1 /usr/lib
5.启动memcached
# /usr/local/memcached/bin/memcached -d -m 256 -p 11211 -u root
OK !!! 搞定! ^^
二、php的memcached模块# tar vxzf memcache-1.5.tgz
安装完后会有类似这样的提示:
# cd memcache-1.5
# /usr/local/php/bin/phpize
# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make
# make installInstalling shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
把这个记住,然后修改php.ini,把
extension_dir = "./"
修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
并添加一行
extension=memcache.so
3、测试脚本
自己写一个PHP程序测试一下吧
<?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;
?>
来源:https://www.cnblogs.com/wencangz/archive/2012/11/07/2758933.html