当前位置: 首页 > news >正文

php与nginx的高速缓存

memcache

PHP的加速模块
本部分是对php的内存加速的配置

1. memcache安装

  609  phpize # 生成./configure文件610  yum install -y autoconf # 安装包611  ls612  phpize613  ls614  ./configure615  make && make install616  ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

vim /usr/local/php/etc/php.ini
systemctl reload php-fpm
php -m | grep memcache

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2. 安装过程问题

php -m 搜索不到memcache模块

在这里插入图片描述
最后发现是文件名字错了,是php.ini不是php-ini
在这里插入图片描述

3. 模块配置

cp example.php memcache.php /usr/local/nginx/html/  # memcache.php是监控页面 # example.php负责存储数据到memcache
yum install -y memcached.x86_64
systemctl enable --now memcached.service

在这里插入图片描述
在这里插入图片描述

vim /usr/local/nginx/html/memcache.php

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 对比磁盘和内存读取的性能

在这里插入图片描述
在这里插入图片描述

4 问题

 client -> nginx -> *.php -> fastcfi_pass -> php-fpm:9000 -> nginx -> client# nginx处理php文件的流程

在处理请求的过程中是通过php-fpm:9000来处理文件,性能还是不够高速,nginx起到的作用很小,需要等待php的处理。

php+nginx高速缓存配置

传统的处理还需要经过PHP,会降低服务器性能。

在这里插入图片描述

openresty

https://openresty.org/cn/

在这里插入图片描述
非常适合前端开发人员
在这里插入图片描述

  1. 安装
tar -zxf openresty-1.21.4.1.tar.gz
cd openresty-1.21.4.1/
./configure --prefix=/usr/local/openresty --with-http_ssl_module --with-http_stub_status_module
# make & make install # 这种写法会出现一定的概率安装不完整
make
make install

在这里插入图片描述

在这里插入图片描述

  1. 配置文件
cd /usr/local/openresty/nginx/conf
cp /usr/local/nginx/conf/nginx.conf . # 为了快速配置可以将nginx的配置文件复制到openresty中
cp /usr/local/nginx/conf/cert.pem .
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

cd /usr/local/openresty/nginx/html
cp /usr/local/nginx/html/index.php .
cp /usr/local/nginx/html/example.php .

在这里插入图片描述
3. 负载均衡

# 负载均衡upstream memcache {server 127.0.0.1:11211;keepalive 512;}

然后通过反向代理,把请求交给负载均衡器

# 在虚拟主机里面定义locationlocation /memc { # /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;}
# 在php目录定义中加入set $key $uri$args;srcache_fetch GET /memc $key;srcache_store PUT /memc $key;

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述


http://www.mrgr.cn/news/9223.html

相关文章:

  • 进程和线程(操作系统part2)
  • 鸿蒙(API 12 Beta3版)【DRM Kit 简介】数字版权保护
  • 【前端】vue数据监测原理
  • Makefile简单使用
  • Matlab基本知识
  • 裸机:串口通信
  • git cherry-pick 合并多个提交
  • linux之网络子系统-tcpdump 原理
  • PHP轻创推客集淘客地推任务平台于一体的综合营销平台系统源码
  • 背包问题(完全背包)
  • Java Web —— 第七天(Mybatis案例 部门管理)
  • EXCEL 分段排序--Excel难题#86
  • 不良贷款只有“贷款逾期”?你知道还有“呆滞”、“呆账”贷款吗?
  • 数学基础 -- 微积分之线性化
  • docker升级docker pull mysql:5.7.37异常
  • 【鼠鼠学AI代码合集#3】简单的数据操作 (pytorch)
  • BCEWithLogitsLoss
  • 大模型在应用开发安全左移实践
  • C#中的压缩与解压缩:掌握内置功能的艺术
  • Matlab自学笔记三十四:表table的排序、查找、提取、删除、计算、与结构数组的转换