Share five PHP7 performance optimization Promotion Tips _php Example

Source: Internet
Author: User

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:

Opcache.file_cache=/tmp

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:

$ make Prof-gen

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.