CentOS环境PHP下安装memcache扩展

前端之家收集整理的这篇文章主要介绍了CentOS环境PHP下安装memcache扩展前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、安装libmemcached库
yum install libmemcached
2、下载并解压memcache文件
wget http://pecl.PHP.net/get/memcache-3.0.8.tgz
tar xzvf memcache-3.0.8.tgz
cd memcache-3.0.8
3、执行PHPize扩展安装程序,假设PHPzie的路径为/usr/local/PHP/bin/PHPize,具体的路径得根据自己的环境修改
[root@naginx memcache-3.0.8]# /usr/local/PHP/bin/PHPize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
4、开始安装扩展memcache
[root@naginx memcache-3.0.8]# ./configure --enable-memcache \
--with-PHP-config=/usr/local/PHP/bin/PHP-config --with-zlib-dir \
make && make install
安装完成后,提示
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20100525/
5、最后修改PHP.ini文件,在zend之前加入如下代码
vim /usr/local/PHP/lib/PHP.ini
extension=/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20100525/memcache.so
6、重新启动PHP-fpm
kill -QUIT pid
/etc/rc.d/init.d/PHP-fpm restart
7、通过PHPinfo()可以查看memcached信息
8、启动memecached
./memcached -d -m 100 -l 192.168.1.120 -p 11211 -u root
9、测试
PHP的memcache测试代码
<?PHP
$mem = new Memcache;
$mem->connect("192.168.1.120",11211) or die("Could not connect");
$version = $mem->getVersion();
echo "Server's version: ".$version."<br/>\n";
$mem->set('hellokey','Hello World',600) or die("Failed to save data at the memcached server");
echo "Store data in the cache (data will expire in 600 seconds)<br/>\n";
$get_result = $mem->get('hellokey');
echo "$get_result is from memcached server.";
?>
查看命中结果
telnet 192.168.1.120 11211
输入命令:status

猜你在找的CentOS相关文章