Home > Backend Development > PHP7 > body text

Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance

coldplay.xixi
Release: 2023-02-17 20:46:01
forward
3199 people have browsed it

Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance

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.


##Recommendation (free): PHP7

PHP7 VS PHP5.6

1. 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"
Copy after login

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

My previous article also introduced: Hugepage to make your PHP7 faster, first in the system Turn on HugePages, and then turn on Opcache's huge_code_pages.

Take my CentOS 6.5 as an example, allocate 512 reserved huge page memory through:

 $sudo sysctl vm.nr_hugepages=512
Copy after login

:

 $ cat /proc/meminfo  | grep HugeAnonHugePages:    106496 kBHugePages_Total:     512HugePages_Free:      504HugePages_Rsvd:       27HugePages_Surp:        0Hugepagesize:       2048 kB
Copy after login

Then Add:

  opcache.huge_code_pages=1
Copy after login

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

Enable Opcache File Cache (experimental). By enabling this, we can let Opcache cache the opcode cache into an external file. For some scripts, there will be obvious problems. Performance improvement.

Add:

 opcache.file_cache=/tmp
Copy after login

to php.ini so that PHP will cache some Opcode binary export files in the /tmp directory, which can exist across the PHP life cycle.

5、PGO

我之前的文章: 让你的PHP7更快(GCC PGO) 也介绍过, 如果你的PHP是专门为一个项目服务, 比如只是为你的Wordpress, 或者drupal, 或者其他什么, 那么你就可以尝试通过PGO, 来提升PHP, 专门为你的这个项目提高性能.

具体的, 以wordpress 4.1为优化场景.. 首先在编译PHP的时候首先:

 $ make prof-gen
Copy after login

然后用你的项目训练PHP, 比如对于Wordpress:

 $ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
Copy after login

也就是让php-cgi跑100遍wordpress的首页, 从而生成一些在这个过程中的profile信息.

最后:

 $ make prof-clean$ make prof-use && make install
Copy after login

这个时候你编译得到的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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template