1. Opcache

Remember to enable Zend Opcache, because PHP7 without Opcache is faster than PHP-5.6 with Opcache enabled, so some people did not enable Opcache during previous tests. Enabling Opcache is as simple as adding the following to the php.ini configuration file:

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1"
Copy the code

2. Use the new compiler

Use a newer compiler. GCC 4.8 or above is recommended because Global Register for opline and execute_data support is enabled for PHP only after GCC 4.8. This will result in a performance improvement of around 5% (measured by Wordpres QPS perspective).

It is also supported in previous versions of GCC 4.8, but we have found that it is buggy, so it must be later than 4.8 to enable this feature.

3. HugePage

First enable HugePages in the system, then enable Huge_code_pages in Opcache.

For example, my CentOS 7.0 passes:

$sudo sysctl vm.nr_hugepages=512
Copy the code

Allocate 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
Copy the code

Then in php.ini add:

opcache.huge_code_pages=1
Copy the code

In this way, PHP will save huge memory pages for its text segment and memory allocation, reducing TLB miss and thereby improving performance

4. Opcache file cache

Enable Opcache File Cache(experimental). By enabling this, we can enable Opcache to Cache the OpCode Cache to external files. For some scripts, there is a significant performance improvement.

In php.ini add:

opcache.file_cache=/tmp
Copy the code

PHP will then Cache some binary export files of Opcode in the/TMP directory, which will exist across the PHP lifecycle.

\

5. PGO

My previous posts: Making your PHP7 faster (GCC PGO) is also mentioned, if your PHP is dedicated to a project, like just your WordPress, or drupal, or whatever, then you can try to use PGO to improve PHP, to improve performance specifically for your project.

Specifically, take wordpress 4.1 as the optimized scenario.. First of all, when compiling PHP, first of all:

$ make prof-gen
Copy the code

Then train PHP with your project, such as WordPress:

$ sapi/cgi/php-cgi -T 100 /www/htdocs/yii2/index.php >/dev/null
Copy the code

This means running phP-CGI through the wordpress homepage 100 times to generate some profile information in the process.

Finally:

$ make prof-clean
$ make prof-use && make install
Copy the code

The above content hope to help you, more free PHP large factory PDF, PHP advanced architecture video materials, PHP wonderful good article can be wechat search concern: PHP open source community

2021 Gold three silver four big factory interview true question collection, must see!

Four years essence OF PHP technical articles collation collection – PHP framework

A collection of four years of quintessential PHP technology articles – Microservices Architecture

Four years of quintessential PHP technology – distributed architecture

Four years of quintessential PHP technology – high concurrency scenarios

Four years essence OF PHP technical articles collation collection – database