前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >鸟哥对于php7提高性能的几点建议

鸟哥对于php7提高性能的几点建议

作者头像
后端技术探索
发布2018-08-09 15:31:39
8650
发布2018-08-09 15:31:39
举报
文章被收录于专栏:后端技术探索后端技术探索

点击关注⬆️nginx⬆️,学习lnmp

(转自鸟哥公众号)

php7怎么最大成程度提高性能,鸟哥有几点建议,引用鸟哥公众号全文如下:

今天临晨的时候, 在我们已经到了12月4日, 但是美国时间还是10月3日的时候, PHP7终于正式发布了.

官方的Release Note可以参看php.net:

"

The PHP development team announces the immediate availability of PHP 7.0.0. This release marks the start of the new major PHP 7 series.

PHP 7.0.0 comes with a new version of the Zend Engine, numerous improvements and new features such as

  • Improved performance: PHP 7 is up to twice as fast as PHP 5.6
  • Significantly reduced memory usage
  • Abstract Syntax Tree
  • Consistent 64-bit support
  • Improved Exception hierarchy
  • Many fatal errors converted to Exceptions
  • Secure random number generator
  • Removed old and unsupported SAPIs and extensions
  • The null coalescing operator (??)
  • Return and Scalar Type Declarations
  • Anonymous Classes
  • Zero cost asserts

"

下载地址(包括Windows): http://www.php.net/downloads.php

为了充分显示出PHP7的最佳性能, 这里有几点Tips给大家:

  1. 记得启用Zend Opcache, 因为PHP7即使不启用Opcache速度也比PHP-5.6启用了Opcache快, 所以之前测试时期就发生了有人一直没有启用Opcache的事情. 启用Opcache非常简单, 在php.ini配置文件中加入: "zend_extension=opcache.so

opcache.enable=1

opcache.enable_cli=1"

2. 使用新一点的编译器, 推荐GCC 4.8以上, 因为只有GCC 4.8以上PHP才会开启Global Register for opline and execute_data支持, 这个会带来5%左右的性能提升(Wordpres的QPS角度衡量)

3. 在服务端开启HugePages, 然后开启Opcache的huge_code_pages.

以我的CentOS 6.5为例, 通过:

"sudo sysctl vm.nr_hugepages=512" 分配512个预留的大页内存

然后在php.ini中:

"opcache.huge_code_pages=1"

这样一来, PHP会把自身的text段, 以及内存分配中的huge都采用大内存页来保存, 减少TLB miss, 从而提高性能.

4. 开启Opcache File Cache(实验性), 通过开启这个, 我们可以让Opcache把opcode缓存缓存到外部文件中, 对于一些脚本, 会有很明显的性能提升.

在php.ini中:

"opcache.file_cache=/tmp"

好了, 欢迎大家测试, 有问题欢迎反馈, 你可以提交bug到bugs.php.net, 或者你可以在微博上@我, 也可以在github上提交issue, 等等. Enjoy!

thanks

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-12-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 nginx 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档