您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。