PHP7和HHVM比较
PHP7的在真实场景的性能确实已经和HHVM相当, 在一些场景甚至超过了HHVM。HHVM的运维复杂, 是多线程模型, 这就代表着如果一个线程导致crash了, 那么整个服务就挂了, 并且它不会自动重启。另外它采用JIT, 那么意味着, 重启以后要预热, 没有预热的情况下, 性能较为糟糕。并且多线程模型调试困难, 这对于追求稳定来说的Web服务来说, 是非常不适合的。
Nginx以及PHP7.0之前的版本可以参考此文:Linux环境Nginx安装与调试以及PHP安装
PHP7.0正式版已经在2015年11月份左右发布,目前是PHP7.0.2版本,本人最早是从2015年8月php7的第一个测试版跟起,现在正式版发布。
linux版本:64位CentOS 6.6
Nginx版本:nginx1.8.0
php版本:php-7.0.2
推荐(免费):PHP7
下载
wget http://php.net/get/php-7.0.2.tar.gz/from/a/mirror
建议安装之前先看看安装帮助文件INSTALL
解压安装
tar zxvf php-7.0.2.tar.gz
cd php-7.0.2
首先查看安装帮助
./configure --help
./configure --prefix=/usr/local/php
–with-curl
–with-freetype-dir
–with-gd
–with-gettext
–with-iconv-dir
–with-kerberos
–with-libdir=lib64
–with-libxml-dir
–with-mysqli
–with-openssl
–with-pcre-regex
–with-pdo-mysql
–with-pdo-sqlite
–with-pear
–with-png-dir
–with-xmlrpc
–with-xsl
–with-zlib
–enable-fpm
–enable-bcmath
–enable-libxml
–enable-inline-optimization
–enable-gd-native-ttf
–enable-mbregex
–enable-mbstring
–enable-opcache
–enable-pcntl
–enable-shmop
–enable-soap
–enable-sockets
–enable-sysvsem
–enable-xml
–enable-zip
如果配置错误,需要安装需要的模块,直接yum一并安装依赖库
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
注意:安装php7beta3的时候有几处配置不过去,需要yum一下,现在php-7.0.2已经不用这样了。
yum -y install curl-devel
yum -y install libxslt-devel
编译安装
make && make install
配置文件
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置
启动
/etc/init.d/php-fpm
查看phpinfo()
php7和php5性能分析比较
生成一个 60 万元素的数组,通过查找key 的方式,来确定key是否存在。
PHP 5.4.44 版
[root@localhost www5.4.44]# time /usr/local/php5.4.44/bin/php search_by_key.php
real 0m0.351s
user 0m0.300s
sys 0m0.050s
PHP 5.5.28 版
[root@localhost www]# time /usr/local/php/bin/php search_by_key.php
real 0m0.361s
user 0m0.304s
sys 0m0.057s
PHP 7.0.0 版
[root@localhost www7]# time /usr/local/php7/bin/php search_by_key.php
real 0m0.114s
user 0m0.097s
sys 0m0.017s
很明显php7的性能是php5的3倍!
配置opcache
官网地址:http://php.net/opcache
使用下列推荐设置来获得较好的 性能:
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
你也可以禁用 opcache.save_comments 并且启用 opcache.enable_file_override。 需要提醒的是,在生产环境中使用上述配置之前,必须经过严格测试。 因为上述配置存在一个已知问题,它会引发一些框架和应用的异常, 尤其是在存在文档使用了备注注解的时候。
vim /usr/local/php7/etc/php.ini
加入
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/opcache.so
重启
killall php-fpm
/etc/init.d/php-fpm
Opcache 状态测试代码(https://gist.github.com/ck-on/4959032)进行演示:
<?php /* OCP - Opcache Control Panel (aka Zend Optimizer+ Control Panel for PHP) Author: _ck_ (with contributions by GK, stasilok) Version: 0.1.6 Free for any kind of use or modification, I am not responsible for anything, please share your improvements * revision history 0.1.6 2013-04-12 moved meta to footer so graphs can be higher and reduce clutter 0.1.5 2013-04-12 added graphs to visualize cache state, please report any browser/style bugs 0.1.4 2013-04-09 added "recheck" to update files when using large revalidate_freq (or validate_timestamps=Off) 0.1.3 2013-03-30 show host and php version, can bookmark with hashtag ie. #statistics - needs new layout asap 0.1.2 2013-03-25 show optimization levels, number formatting, support for start_time in 7.0.2 0.1.1 2013-03-18 today Zend completely renamed Optimizer+ to OPcache, adjusted OCP to keep working 0.1.0 2013-03-17 added group/sort indicators, replaced "accelerator_" functions with "opcache_" 0.0.6 2013-03-16 transition support as Zend renames product and functions for PHP 5.5 (stasilok) 0.0.5 2013-03-10 added refresh button (GK) 0.0.4 2013-02-18 added file grouping and sorting (click on headers) - code needs cleanup but gets the job done 0.0.2 2013-02-14 first public release * known problems/limitations: Unlike APC, the Zend OPcache API - cannot determine when a file was put into the cache - cannot change settings on the fly - cannot protect opcache functions by restricting execution to only specific scripts/paths * todo: Extract variables for prefered ordering and better layout instead of just dumping into tables File list filter */ // ini_set('display_errors',1); error_reporting(-1); if ( count(get_included_files())>1 || php_sapi_name()=='cli' || empty($_SERVER['REMOTE_ADDR']) ) { die; } // weak block against indirect access $time=time(); define('CACHEPREFIX',function_exists('opcache_reset')?'opcache_':(function_exists('accelerator_reset')?'accelerator_':'')); if ( !empty($_GET['RESET']) ) { if ( function_exists(CACHEPREFIX.'reset') ) { call_user_func(CACHEPREFIX.'reset'); } header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) ); exit; } if ( !empty($_GET['RECHECK']) ) { if ( function_exists(CACHEPREFIX.'invalidate') ) { $recheck=trim($_GET['RECHECK']); $files=call_user_func(CACHEPREFIX.'get_status'); if (!empty($files['scripts'])) { foreach ($files['scripts'] as $file=>$value) { if ( $recheck==='1' || strpos($file,$recheck)===0 ) call_user_func(CACHEPREFIX.'invalidate',$file); } } header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) ); } else { echo 'Sorry, this feature requires Zend Opcache newer than April 8th 2013'; } exit; } ?>nbsp;html>
<p> </p><h1 id="a-Opcache-Control-Panel-a"><a>Opcache Control Panel</a></h1> <p> <a>Details</a> <a>Files</a> <a>Reset</a> <?php if ( function_exists(CACHEPREFIX.'invalidate') ) { ?> <a>Recheck</a> <?php } ?> <a>Refresh</a> </p> <?php if ( !function_exists(CACHEPREFIX.'get_status') ) { echo '<h2>Opcache not detected?'; die; } if ( !empty($_GET['FILES']) ) { echo '<h2 id="files-cached">files cached</h2>'; files_display(); echo '
以上是介绍Linux环境下PHP7.0安装的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver Mac版
视觉化网页开发工具

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),