memcache

#############给PHP作memcache缓存
tar  xf memcache-2.2.5.tgz
vim ~/.bash_profile
:/usr/local/lnmp/php/bin
source ~/.bash_profile
cd memcached
phpize
./configure -enable-memcache --with-php-config=/usr/local/lnmp/php/bin/php-config
make && make install


vim /usr/local/lnmp/php/etc/php.ini
/extension=
随便修改一个
extension=memcache.so
yum install -y memcached
配置文件在 /etc/sysconfig/memcached

/etc/init.d/memcached start

 

 

cp memcache.php example.php /usr/local/lnmp/nginx/html/

vim /usr/local/lnmp/nginx/html/memcache.php
修改密码和下面
$MEMCACHE_SERVERS[] = '172.25.11.1:11211';
注释第二行

/etc/init.d/memcached reload
/etc/init.d/php-fpm reload
nginx -s reload
ab -c 10 -n 5000 http://172.25.11.1/example.php
ab -c 10 -n 5000 http://172.25.11.1/index.php
10并发 5000次请求
         

telnet localhost 11211

set name 0 5 6 缓存五秒  最多缓存6个字符
输入字符
get name测试
delete name
quit 退出

 

#########对nginx 作缓存
openresty软件
自带nginx 所以需要关了原来的nginx
nginx -s stop

tar zxf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
ls
./configure
gmake && gmake install

在/usr/local/openresty

cp /usr/local/lnmp/nginx/html/memcache.php /usr/local/openresty/nginx/html

cp /usr/local/lnmp/nginx/html/example.php /usr/local/openresty/nginx/html


vim /usr/local/openresty/nginx/conf/nginx.conf


http函数中添加
    upstream memcache {
        server localhost:11211;
        keepalive 512;
    }


56行加入下面

location /memc {
    internal;
    memc_connect_timeout 100ms;
    memc_send_timeout 100ms;
    memc_read_timeout 100ms;
    set $memc_key $query_string;
    set $memc_exptime 300;  #过期时间
    memc_pass memcache; #访问到/memc目录时,处理到反向代理模块
}

打开php模块
##memc  srcache 两个模块

        location ~ \.php$ {
            set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }

/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload
/usr/local/openresty/nginx/sbin/nginx

ab -c 10 -n 5000 http://172.25.11.1/example.php
ab -c 10 -n 5000 http://172.25.11.1/index.php
会发现速度快了更多

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值