PHP与各加速工具的性能对比
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 Xcache简介 前面已经介绍了PHP加速器的原理和功用(参见LAMP架构之PHP-FPM 服务器),xcache作为目前使用广泛的PHP加速器之一,其性能比早期的eAccelerator加速器要优良,故本次就对比一下PHP程序在
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
Xcache简介
前面已经介绍了PHP加速器的原理和功用(参见LAMP架构之PHP-FPM 服务器),xcache作为目前使用广泛的PHP加速器之一,其性能比早期的eAccelerator加速器要优良,故本次就对比一下PHP程序在执行时加速器xcache对其的性能影响。
安装xcache
复制代码
# 安装
tar xf xcache-3.0.3.tar.gz
cd xcache-3.0.3
/usr/local/php/bin/phpize # xcache是作为php的外接模块安装的
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install
# 安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
# 编辑php.ini,整合php和xcache:
# 首先将xcache提供的样例配置导入php.ini
mkdir /etc/php.d # 这是前面安装PHP时配置的配置文件扫描目录
cp xcache.ini /etc/php.d # xcache.ini文件在xcache的源码目录中。
# 接下来编辑/etc/php.d/xcache.ini,找到extension开头的行,修改为如下行:
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
# 如果php.ini文件中有多条extension指令行,要确保此新增的行排在第一位。
# 查看xcache是否已安装成功:
/usr/local/php/bin/php -m |grep -i xcache
复制代码
Opcache简介
新一代PHP加速器,由Zend公司研发,其实现原理与Xcache类似,都是把PHP执行后的数据缓冲到内存中从而避免重复的编译过程,能够直接使用缓冲区已编译的代码从而提高速度,降低服务器负载,但性能却比Xcache更加优越,详见测试结果
安装Opcache
复制代码
wget http://pecl.php.net/get/zendopcache-7.0.2.tgz
tar xzf zendopcache-7.0.2.tgz
cd zendopcache-7.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
# 配置文件设置,可直接在php.ini的最后添加如下内容,但在此在PHP配置文件的扫描目录php.d下配置新文件opcache.ini,易于管理,php-config-scan-dir是在编译安装PHP时定义的
# vi /etc/php.d/opcache.ini
[opcache]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/opcache.so
opcache.memory_consumption=128 # 分配的内存大小,单位MB,即能够存储多少预编译的PHP代码
opcache.interned_strings_buffer=8 # interned字符串占内存大小,单位MB
opcache.max_accelerated_files=4000 # 允许缓存的文件最大数量
opcache.revalidate_freq=60 # 多长时间检查文件时间戳,以改变共享内存分配,单位为s
opcache.fast_shutdown=1 # 是否开启快速关闭队列功能,1为开启
opcache.enable_cli=1 # 允许缓存CLI下的PHP程序
#检查模块安装成功:/usr/local/php/bin/php -m |grep -i opcache
复制代码
hhvm简介
HipHop VM(HHVM)是Facebook推出的用来执行PHP代码的虚拟机,它是一个PHP的JIT(Just-In- Time)编译器,同时具有产生快速代码和即时编译的优点;
hhvm将PHP代码编译转换成C++程序来执行,执行效率得到显着提升;
根据 Facebook透漏,HHVM在速度方面获得了显着改进,比目前使用的PHP解释器快60%,而使用内存减少90%
安装hhvm
因为目前hhvm还处以研发阶段,国内用于生产环境的还很少,安装所需的环境比较复杂(如CentOS6.5下的boost-system和boost-filesystem的版本就过低),故本人还在调试测试阶段,等出了测试结果,再将hhvm的测试结果一并贴出。
测试步骤
# 另找一台虚拟机,对HTTPD服务器(192.168.1.110)进行压力测试
# 测试工具使用Apache自带的基准测试工具ab即可
# 测试方法如下:
ab -c 20 -n 2000 http://192.168.1.110:8080/index.php
# 注:测试采用20并发,在不影响访问的情况下,查看xcache加速器的加速效果;测试页面使用上一讲刚部署的phpMyAdmin的登录页面index.php即可
# 注:为了更好的测试出PHP加速器的缓存特性,可连续多测试几次,得到稳定值

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Binance Square is a social media platform provided by Binance Exchange, aiming to provide users with a space to communicate and share information related to cryptocurrencies. This article will explore the functions, reliability and user experience of Binance Plaza in detail to help you better understand this platform.

phpMyAdmin simplifies MySQL database management through the web interface. 1) Create databases and tables: Use graphical interface to operate easily. 2) Execute complex queries: such as JOIN query, implemented through SQL editor. 3) Optimization and best practices: including SQL query optimization, index management and data backup.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Python can run on a variety of platforms, including our common ones: Windows, Unix, Linux, and Macintosh. This article will introduce in detail the process of installing Python in Windows operating system. My operating system is Windows 7, 32-bit version. When installing Python, we can choose to install it from the source code or select the already compiled binary version for installation. I chose the latter here. Step 1 Download the installation package. We download the installation package of Python from the official Python website: http://www.python.org. The version I selected is: python-3.3.2.msi click to download, I

The latest download tutorial for Ouyi OKX6.118.0 version: 1. Click on the quick link in the article; 2. Click on the download (if you are a web user, please register the information first). The latest Android version v6.118.0 optimizes some functions and experiences to make trading easier. Update the app now to experience a more extreme trading experience.

Linuxoffersextensiveopen-sourcesoftwareandcustomization,butlackssomecommercialapplications;Windowsexcelsincommercialsoftwareandgaming,buthaslesscustomization.Linuxusespackagemanagersforeasysoftwareinstallationandprovidescommunity-drivenrepositories,w

Linuxoffersmoregranularcontroloverloggingandauditing,whileWindowsprovidesamorecentralizedsystem.1)Linuxusestoolslikesyslog,rsyslog,andjournaldforcustomizablelogging.2)WindowsusestheEventViewerforcentralizedlogmanagement.3)Linuxisidealforenvironmentsn

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.
