php扩展memcached的作用是为了支持数据库缓存服务器,首先需要先编译安装好php,php具体安装步骤可参考本站(请在右上角搜索即可),安装好php之后,就可以用phpize安装memcached扩展。
下载libmemcached
https://launchpad.net/libmemcached/+download
# cd /usr/local/src # wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
安装libmemcached
# tar zxf libmemcached-1.0.18.tar.gz # cd libmemcached-1.0.18 # ./configure --prefix=/usr/local/libmemcached --with-memcached # make # make install
下载memcached扩展
http://pecl.php.net/package/memcached
# cd /usr/local/src # wget http://pecl.php.net/get/memcached-2.2.0.tgz
安装memcached扩展
# /usr/local/php/bin/phpize # tar zxvf memcached-2.2.0.tgz # cd memcached-2.2.0 # ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl # make # make install
安装完成后,会在php的模块目录下生产memcached.so模块文件
修改php.ini,假如如下内容
[memcached] extension=memcached.so
然后重启apache或者php-fpm,查看phpinfo页面是否加载成功,通过以下方法测试php客户端memcache连接memcached服务器端是否正常
在apache网站根目录下建立memcache.php文件
# vim memcache.php
添加如下内容:
$memcache->set('key', 'Memcache test successful!', 0, 60); $result = $memcache->get('key'); unset($memcache); echo $result; ?>