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
/usr/local/php/sbin/php-fpm
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', 0, 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
memcached 缓存信息查看(主要是discuz 3(修改config_global.php的memcached配置信息)设置完成后的缓存信息)
stats cachedump 1 0
ITEM hellokey [11 b; 1441724619 s]
ITEM 8bwmS2_home_follow_2 [6 b; 1441810396 s]
ITEM 8bwmS2_pluginlanguage_system [0 b; 1441710021 s]
ITEM 8bwmS2_cronnextrun [10 b; 1441710021 s]
ITEM 8bwmS2_userapp [6 b; 1441710021 s]
ITEM 8bwmS2_magic [6 b; 1441710021 s]
ITEM 8bwmS2_attachtype [6 b; 1441710021 s]
ITEM 8bwmS2_relatedlink [6 b; 1441710021 s]
ITEM 8bwmS2_posttable_info [0 b; 1441710021 s]
ITEM 8bwmS2_threadtable_info [0 b; 1441710021 s]
ITEM 8bwmS2_plugin [6 b; 1441710021 s]
ITEM 8bwmS2_threadtableids [0 b; 1441710021 s]
ITEM 8bwmS2_domainwhitelist [6 b; 1441710021 s]
ITEM 8bwmS2_albumcategory [6 b; 1441710021 s]
ITEM 8bwmS2_forum_guide [6 b; 1441710021 s]
ITEM 8bwmS2_historyposts [3 b; 1441710021 s]
ITEM 8bwmS2_heats [6 b; 1441710021 s]
ITEM 8bwmS2_announcements [6 b; 1441710021 s]
ITEM 8bwmS2_adminmenu [6 b; 1441710021 s]
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。