PHP添加扩展模块及openresty(缓存前移),扩展模块openresty


Memcached

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据 库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信

一·php模块扩展

下载 memcache-2.2.5.tgz

[root@server1 ~]# tar zxf memcache-2.2.5.tgz    ##解压
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/php/bin/
[root@server1 bin]# pwd
/usr/local/lnmp/php/bin
[root@server1 bin]# cd
[root@server1 ~]# vim .bash_profile    
##增加路径,写入:
     10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin:/usr/local/lnmp/php/bin
[root@server1 ~]# source .bash_profile
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# phpize 

编译三部曲:

[root@server1 memcache-2.2.5]# ./configure 
[root@server1 memcache-2.2.5]# make
[root@server1 memcache-2.2.5]# make install 

修改配置文件:

[root@server1 memcache-2.2.5]# cd /usr/local/
[root@server1 local]# cd lnmp/php/etc/
[root@server1 etc]# vim php.ini 
编辑:
     873 extension=memcache.so
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server1 etc]# php -m |grep memcache
memcache
[root@server1 etc]# cd
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# yum install memcached -y
[root@server1 memcache-2.2.5]# /etc/init.d/memcached start
[root@server1 memcache-2.2.5]# netstat -antlp |grep :11211
[root@server1 html]# vim memcache.php 

 

在 memcache.php 文件

网页访问:



物理机做压力测试:

ab -c 10 -n 1000 http://172.25.41.1/memcache.php

ab -c 10 -n 1000 http://172.25.41.1/example.php

二·缓存前移

安装包: openresty-1.13.6.1.tar.gz

[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz 
[root@server1 ~]# cd openresty-1.13.6.1

编译三部曲:

[root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio
[root@server1 openresty-1.13.6.1]# gmake
[root@server1 openresty-1.13.6.1]# gmake   install

配置文件:

[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t   ##检测
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx   ##打开


 

网页访问:

物理机压力测试:

ab  -c  10  -n  1000  http://172.25.41.1/index.php

ab  -c  10 -n 1000 http://172.25.41.1/example.php

相关内容

    暂无相关文章