A few Tips to make PHP7 reach the highest performance

1. Opcache

Remember to enable Zend Opcache, because PHP7 is faster than PHP-5.6 with Opcache enabled even if Opcache is not enabled, so some people have not enabled Opcache during the previous testing period. Enabling Opcache is very simple, add it to the php.ini configuration file :

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1"

2. Use the new compiler

Use a newer compiler, recommend GCC 4.8 or higher, because only GCC 4.8 or higher PHP will enable Global Register for opline and execute_data support, this will bring about 5% performance improvement (Wordpres QPS perspective)
In fact, GCC versions before 4.8 are also supported, but we found that it supports bugs, so it must be version 4.8 or higher to enable this feature.

3. HugePage

My previous article also introduced: To make your PHP7 faster Hugepage, first open HugePages in the system, and then open Opcache’s huge_code_pages.
Take my CentOS 6.5 as an example, through:

$sudo sysctl vm.nr_hugepages=512

Allocate 512 reserved large pages of memory:

$ cat /proc/meminfo | grep Huge
AnonHugePages: 106496 kB
HugePages_Total: 512
HugePages_Free: 504
HugePages_Rsvd: 27
HugePages_Surp: 0
Hugepagesize: 2048 kB

Then add in php.ini:

opcache.huge_code_pages=1

In this way, PHP will save its own text segment and the huge memory allocation in large memory pages to reduce TLB miss, thereby improving performance.

4. Opcache file cache

Turn on Opcache File Cache (experimental).By turning on this, we can let Opcache cache the opcode cache to external files. For some scripts, there will be a significant performance improvement.
Add in php.ini:

opcache.file_cache=/tmp

In this way, PHP will cache some Opcode binary export files in the /tmp directory, which can exist across the PHP life cycle.

5. PGO

My previous article: Make your PHP7 faster (GCC PGO) also introduced, if your PHP is dedicated to a project, such as just for your WordPress, or drupal, or whatever, then you can try to pass PGO, to improve PHP, specifically to improve the performance of your project.
Specifically, use wordpress 4.1 as the optimization scenario.. First of all, when compiling PHP:

make prof-gen

Then use your project to train PHP, for example for WordPress:

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

That is, let php-cgi run 100 times on the homepage of wordpress to generate some profile information in this process.
At last:

$ make prof-clean
$ make prof-use && make install

The PHP7 you compile at this time is the highest-performance compiled version tailored for your project.
That’s it for the time being, I will add it later when I think of it, everyone is welcome to try it, thanks.