memcache
PHP的加速模块
 本部分是对php的内存加速的配置
1. memcache安装
  609  phpize # 生成./configure文件
  610  yum install -y autoconf # 安装包
  611  ls
  612  phpize
  613  ls
  614  ./configure
  615  make && make install
  616  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/

 非常适合前端开发人员
 
- 安装
 
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
 


- 配置文件
 
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;
    }
 
然后通过反向代理,把请求交给负载均衡器
# 在虚拟主机里面定义location
  location /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;
 













![OSError:[WinError -2146959355] 服务器运行失败](https://i-blog.csdnimg.cn/direct/821d9f504e76453bada32aade818a63b.png#pic_center)









