日期:2014-05-17  浏览次数:20473 次

Memcached - PHP 安装&使用

下载Memcached:
http://danga.com/memcached/download.bml

安装:
下载安装libevent,已安装可跳过:
下载地址:http://www.monkey.org/~provos/libevent/

Memcached For PHP Module下载地址:
http://pecl.php.net/package/memcache
http://cn.php.net/manual/zh/ref.memcache.php

安装Memcached服务端

root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install

安装完毕重启服务:

root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root



安装PHP模块

root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# 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


安装完毕,测试:

PHP代码

<?php?

? $memcache ?=? new ?Memcache;? //创建一个memcache对象 ?

? $memcache ->connect( 'localhost' ,?11211)?