centos yum安裝memcached及php memcache擴充教程,centosmemcached
注意事項:
1 安裝時注意許可權問題 sudo
2 需先啟動memcache服務 php才能測試
Memcached是高效能的,分布式的記憶體對象緩衝系統,用於在Live App中減少資料庫負載,提升訪問速度。
開始安裝memcache
尋找相關軟體包
#yum search memcache
有了,現在可以安裝了
#yum -y install –enablerepo=rpmforge memcached php-pecl-memcache
#如果提示沒安裝成功 yum update一下 然後再執行命令 成功即把memcache服務端和php memcache擴充都安裝好 會在/usr/lib64/php/modules/memcache.so
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* atomic: mirrors.neusoft.edu.cn
* base: mirrors.btte.net
* extras: mirrors.yun-idc.com
* updates: mirrors.btte.net
Setting up Install Process
Error: Nothing to do
驗證一下安裝結果
#memcached -h
#php -m|grep memcache
設定開機啟動
#chkconfig memcached on
啟動memcached
#service memcached start
到這裡memcache服務端安裝成功 測試安裝是否成功
[root@localhost usr]# php -m|grep memcache
memcache
[root@localhost usr]# lsof -i tcp:11211
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 3399 memcached 26u IPv4 12677364 0t0 TCP *:memcache (LISTEN)
memcached 3399 memcached 27u IPv6 12677365 0t0 TCP *:memcache (LISTEN)
已經在偵聽 說明成功 會產生memcache.so 32位在/usr/lib/中 64位在/usr/lib64/
接下來載入php memcache擴充
php.ini中開啟 extension=/usr/lib64/php/modules/memcache.so
/etc/init.d/httpd restart #重啟Apache
需先啟動memcache 然後重啟php-fpm 即可看到擴充 不需重啟nginx
service php-fpm restart
代碼測試:
mem.php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test2211!', 0, 60);
$val = $mem->get('key');
echo $val;