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 for it to maximize its Performance, there are still a few things I would like to remind you.
1. Opcache
## Remember to enable Zend Opcache, because PHP7 is faster even if Opcache is not 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, configure it in php.iniAdd to file :
zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1"
2. Use a new compiler
Use a newer compiler, GCC 4.8 or above is recommended, because only GCC 4.8 or above PHP will enable Global Register for opline and execute_data support, 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 it supports There is a bug, so it must be version 4.8 or above to enable this feature.3. HugePage
I also introduced it in my previous article: Make your PHP7 more To quickly use Hugepage, first enable HugePages in the system, and then enable Opcache's huge_code_pages.Take my CentOS 6.5 as an example, pass:$sudo sysctl vm.nr_hugepages=512Allocate 512 reserved large page memory:
$ cat /proc/meminfo | grep Huge AnonHugePages: 106496 kB HugePages_Total: 512 HugePages_Free: 504 HugePages_Rsvd: 27 HugePages_Surp: 0 Hugepagesize: 2048 kB
opcache.huge_code_pages=1
4. Opcache file cache
Enable Opcache File Cache (experimental), by turning this on, we can let Opcache cache opcodecache into an external file. For some scripts, there will be a significant performance improvement.In php.ini Add:
opcache.file_cache=/tmp
life cycle.
5. PGO
My previous article: Make your PHP7 faster (GCC PGO) also introduced that if your PHP is specifically for one project, such as just for your WordPress, or drupal, Or something else, then you can try to improve PHP through PGO, specifically to improve the performance of your project. Specifically, take WordPress 4.1 as the optimization scenario. First, when compiling PHP:$ make prof-gen
$ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
$ make prof-clean $ make prof-use && make install
The above is the detailed content of Summary of 5 php7 performance optimization tips. For more information, please follow other related articles on the PHP Chinese website!