#############给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
会发现速度快了更多