首页 LAMP教程PHP的加速器配置介绍

LAMP实战案例:实现PowerDNS 应用部署

php-fpm模式实现LAMP

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

php的加速器

php的加速器:基于PHP的特殊扩展机制如opcode缓存扩展也可以将opcode缓存于php的共享内存中,从而可以让同一段代码的后续重复执行时跳过编译阶段以提高性能。这些加速器并非真正提高了opcode的运行速度,而仅是通过分析opcode后并将它们重新排列以达到快速执行的目的

常见的第三方php加速器

1、APC (Alternative PHP Cache)
遵循PHP License的开源框架,PHP opcode缓存加速器,目前的版本不适用于PHP 5.4
项目地址:http://pecl.php.net/package/APC
2、eAccelerator
源于Turck MMCache,早期的版本包含了一个PHP encoder和PHP loader,目前encoder已经不在支持。项目地址 :http://eaccelerator.net/
3、XCache
快速而且稳定的PHP opcode缓存,经过严格测试且被大量用于生产环境。项目地址:http://xcache.lighttpd.net/,收录EPEL源
4、Zend Optimizer和Zend Guard Loader
Zend Optimizer并非一个opcode加速器,它是由Zend Technologies为PHP5.2及以前的版本提供的一个免费、闭源的PHP扩展,其能够运行由Zend Guard生成的加密的PHP代码或模糊代码。 而Zend Guard Loader则是专为PHP5.3提供的类似于Zend Optimizer功能的扩展。项目地址http://www.zend.com/en/products/guard/runtime-decoders
5、NuSphere PhpExpress
NuSphere的一款开源PHP加速器,它支持装载通过NuSphere PHP Encoder编码的PHP程序文件,并能够实现对常规PHP文件的执行加速。项目地址,http://www.nusphere.com/products/phpexpress.htm

实现 xcache 加速 php 5.X

编译php-xcache加速访问,支持php 5.6版以下
官网:http://xcache.lighttpd.net/wiki/ReleaseArchive

案例:CentOS 7上安装清华源的php56,并编译安装 xcache加速

[root@centos7 ~]#yum -install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@centos7 ~]#yum -y install php56-php php56-php-mysqlnd mariadb-server
[root@centos7 ~]#systemctl enable --now httpd mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@centos7 ~]#mysql
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'magedu';
[root@centos7 ~]#tar xvf wordpress-5.3.2-zh_CN.tar.gz  -C /var/www/html
[root@centos7 ~]#cd /var/www/html
[root@centos7 ~]#chown -R apache.apache wordpress/
[root@centos8 ~]#ab -c 10 -n 100 http://10.0.0.7/wordpress/
......
Requests per second:    3.16 [#/sec] (mean)
......

#安装编译xcache
[root@centos7 ~]#yum -y install gcc  php56-php-devel
#下载并解压缩xcache-3.2.0.tar.bz2
[root@centos7 ~]#tar xf xcache-3.2.0.tar.gz
#生成编译环境
[root@centos7 ~]#cd xcache-3.2.0/
[root@centos7 xcache-3.2.0]#/opt/remi/php56/root/usr/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@centos7 xcache-3.2.0]#./configure --enable-xcache --with-php-config=/opt/remi/php56/root/usr/bin/php-config
[root@centos7 xcache-3.2.0]#make && make install
...省略...
Installing shared extensions:     /opt/remi/php56/root/usr/lib64/php/modules/

[root@centos7 xcache-3.2.0]#cat xcache.ini  >> /opt/remi/php56/root/etc/php.ini
#安装base源中执行即可cp xcache.ini  /etc/php.d/
[root@centos7 ~]#systemctl restart httpd.service

#测试性能
[root@centos8 ~]#ab -c10 -n 100 http://LAMP服务器/wordpress
Requests per second:    7.26 [#/sec] (mean)

opcache加速php 7.X

[root@centos8 ~]#dnf install php-opcache
[root@centos8 ~]#cat  /etc/php.ini
[opcache]
zend_extension=opcache.so                            
opcache.enable=1

范例:CentOS 8 实现opache 加速

[root@centos8 ~]#dnf -y install httpd php php-mysqlnd mariadb-server php-opcache php-json
[root@centos8 ~]#rpm -ql php-opcache
/etc/php.d/10-opcache.ini
/etc/php.d/opcache-default.blacklist
/usr/lib/.build-id
/usr/lib/.build-id/71
/usr/lib/.build-id/71/55ebb00f7ebcab9d708c1d5c7b7e634cce259c
/usr/lib64/php/modules/opcache.so
[root@centos8 ~]#grep opcache /etc/php.d/10-opcache.ini
zend_extension=opcache
opcache.enable=1
...省略...

#加速前
#禁用加速
[root@centos8 ~]#vim /etc/php.d/10-opcache.ini
opcache.enable=0
[root@centos8 ~]#systemctl restart php-fpm
[root@centos7 ~]#ab -c 10 -n 100 http://10.0.0.8/wordpress/
......
Requests per second:    4.31 [#/sec] (mean)
......

#启用加速
[root@centos8 ~]#vim /etc/php.d/10-opcache.ini
opcache.enable=1
[root@centos8 ~]#systemctl restart php-fpm

##加速后
[root@centos7 ~]#ab -c 10 -n 100 http://10.0.0.8/wordpress/
......
Requests per second:    19.76 [#/sec] (mean)
......

本文链接:https://www.yunweipai.com/36095.html

LAMP实战案例:实现PowerDNS 应用部署

php-fpm模式实现LAMP

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部