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
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 \
make && make install
安装完成后,提示
Build complete.
Don't forget to run 'make test'.
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
$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