PHP7 has released, as the largest version upgrade in PHP10 years, the biggest performance upgrade, PHP7 in the multiple-release test has shown a significant performance improvement, however, in order to allow it to play the most performance, I still have a few things to remind.
1. Opcache
Remember to enable Zend Opcache, because PHP7 even if the Opcache speed is not enabled than PHP-5.6 enabled Opcache faster, so the previous test period has occurred someone has not enabled the opcache of things. Enabling Opcache is very simple, adding in the php.ini configuration file:
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1 "
2. Using the new compiler
Using a new compiler, GCC is recommended for more than 4.8, because only gcc 4.8 or more PHP will open the global Register for Opline and execute_data support, this will bring about 5% performance improvement ( Wordpres QPS angle measurement)
In fact, the previous version of GCC 4.8 also supported, but we found that it supports a bug, so it must be more than 4.8 version to open this feature.
3. Hugepage
My previous article also introduced: Let your PHP7 faster hugepage, first in the system to open hugepages, and then open Opcache huge_code_pages.
Take my CentOS 6.5 for example, by:
$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 the php.ini:
Copy Code code as follows:
Opcache.huge_code_pages=1
As a result, PHP uses a large memory page for its own text segment, as well as huge in memory allocations, to reduce the TLB miss to improve performance.
4. opcache File Cache
Open Opcache File Cache (experimental), by opening this, we can let Opcache cache the opcode cache into the external file, for some scripts, there will be a significant performance improvement.
Add in php.ini:
Copy Code code as follows:
This allows PHP to cache some opcode binary export files in the/tmp directory, which can exist across the PHP lifecycle.
5. PGO
My previous article: Let your PHP7 faster (GCC PGO) also introduced, if your PHP is dedicated to a project services, such as just for your WordPress, or Drupal, or whatever, then you can try to upgrade PHP through PGO, Specifically for your project to improve performance.
Specifically, to WordPress 4.1 for the optimization scene. First of all, when compiling PHP:
Copy Code code as follows:
Then use your project to train PHP, for example, for WordPress:
Copy Code code as follows:
$ sapi/cgi/php-cgi-t 100/home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
That is, let php-cgi run 100 times the homepage of WordPress, thus generating some profile information in this process.
At last:
$ make Prof-clean
$ make prof-use && make install
The PHP7 you compile this time is the most high-performance compiled version that is tailored to your project.
For the time being so much, later think up and add, welcome everyone to try, thanks
The above cloud-Habitat Community small series to share five PHP7 performance optimization skills, I hope you like.