准备:
Memcached下载地址:http://www.danga.com/memcached/
libevent下载地址: http://monkey.org/~provos/libevent/
安装步骤:
1. 下载libevent & memcached 源码包
memcached-1.2.2.tar.gz
2. 解压缩 libevent-1.3.tar.gz ,编译安装
# cd libevent-1.3
# ./configure --prefix=/usr/local/libevent
# make ; make install
3. 解压缩 memcached-1.2.2.tar.gz, 编译安装
# cd memcached-1.2.2
# ./configure --prefix=/usr/local/memchached --with-libevent=/usr/local/libevent
# make;make install
4. 作软连接,否则运行memcached的时候将找不到libevent模块
5.启动memcached
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 install
安装完后会有类似这样的提示:Installing 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;
?>
源文 : http://wangchengtai.blog.hexun.com/37920747_d.html