您的位置:首页 > 数据库 > Memcache

centos yum安装memcached及php memcache扩展

2016-07-06 18:19 721 查看
注意事项:

1 安装时注意权限问题 sudo

2 需先启动memcache服务 php才能测试

Memcached是高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。

开始安装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

<?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;

?>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: