1.查找memcached源是否存在
yum search memcached
image.png
2.安裝
yum -y install –enablerepo=rpmforge memcached php-pecl-memcache
image.png
3.驗(yàn)證是否安裝成功
memcached -h //會輸出一些幫助信息
4.設(shè)置開機(jī)自動啟動
chkconfig memcached on
image.png
5.啟動服務(wù)
service memcached start
image.png
6.測試服務(wù)端是否安裝成功
php -m|grep memcache
7.查看端口號是否正常
lsof -i tcp:11211
8.在php.ini中添加配置
在php.ini中添加
extension=/usr/lib64/php/modules/memcache.so。
9.輸出phpinfo()查看是否配置成功。
echo phpinfo();
image.png
9.簡單測試代碼
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test, Hello World!--Pc.Lee', 0, 0);
$val = $mem->get('key');
echo $val;





