PHP7 has been released. As the largest version upgrade and the largest performance upgrade of PHP in 10 years, PHP7 has shown obvious performance improvements in multiple tests. However, in order to make It can exert its maximum performance, but I still have a few things to remind you.
PHP7 VS PHP5.61. Opcache
Remember to enable it Zend Opcache, because PHP7 is faster even without Opcache enabled than PHP-5.6 with Opcache enabled, so some people did not enable Opcache during the previous testing period. Enabling Opcache is very simple, just add:# in the php.ini configuration file. ##zend_extension=opcache.soopcache.enable=1opcache.enable_cli=1"
2. Use a new compilerUse a newer compiler, GCC 4.8 or above is recommended, because only GCC 4.8 or above PHP can Global Register for opline and execute_data support will be enabled, which will bring about a 5% performance improvement (measured from the QPS perspective of Wordpres)
In fact, versions before GCC 4.8 also support it, but we found that there are bugs in its support , so it must be version 4.8 or above to enable this feature.
3. HugePage
Take my CentOS 6.5 as an example, allocate 512 reserved huge page memory through:
$sudo sysctl vm.nr_hugepages=512
:
$ cat /proc/meminfo | grep HugeAnonHugePages: 106496 kBHugePages_Total: 512HugePages_Free: 504HugePages_Rsvd: 27HugePages_Surp: 0Hugepagesize: 2048 kB
Then Add:
opcache.huge_code_pages=1
In this way, PHP will use large memory pages to save its own text segment and huge memory allocation, reducing TLB misses and improving performance.
4. Opcache file cache
opcache.file_cache=/tmp
我之前的文章: 让你的PHP7更快(GCC PGO) 也介绍过, 如果你的PHP是专门为一个项目服务, 比如只是为你的Wordpress, 或者drupal, 或者其他什么, 那么你就可以尝试通过PGO, 来提升PHP, 专门为你的这个项目提高性能.
具体的, 以wordpress 4.1为优化场景.. 首先在编译PHP的时候首先:
$ make prof-gen
然后用你的项目训练PHP, 比如对于Wordpress:
$ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
也就是让php-cgi跑100遍wordpress的首页, 从而生成一些在这个过程中的profile信息.
最后:
$ make prof-clean$ make prof-use && make install
这个时候你编译得到的PHP7就是为你的项目量身打造的最高性能的编译版本.
暂时就这么多吧, 以后想起来再加, 欢迎大家尝试, thanks
更多免费推荐:PHP7教程
The above is the detailed content of Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance. For more information, please follow other related articles on the PHP Chinese website!