Tips for improving performance of five PHP7 instances

Source: Internet
Author: User
This article will share with you five tips for optimizing and improving the performance of PHP7. If you are interested in improving the performance of php7, you can learn more. PHP7 has been released as the biggest version upgrade of phpin the past 10 years, for the biggest performance upgrade, PHP 7 has shown significant performance improvement in multiple tests. However, I still want to remind you of a few things to maximize the performance.

1. Opcache

Remember to enable Zend Opcache, because PHP 7 is faster than the PHP-5.6 to enable Opcache even if Opcache is not enabled, so there was a problem that someone had never enabled Opcache before the test period. it is very easy to enable Opcache. add the following to the ini configuration file:

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

2. Use the new Compiler

To use a new compiler, we recommend GCC 4.8 or above, because only GCC 4.8 or above PHP will enable Global Register for opline and execute_data support, this will increase the performance by about 5% (QPS of Wordpres)

In fact, GCC versions earlier than 4.8 also support this feature, but we found that it supports bugs, so this feature must be enabled only in Versions later than 4.8.

3. HugePage

My previous article also introduced: To make your PHP7 faster Hugepage, first enable HugePages in the system, and then enable the Opcache huge_code_pages.

Take my CentOS 6.5 as an example:

$ Sudo sysctl vm. nr_hugepages = 512

Allocate up to 512 reserved large page memory:

$ cat /proc/meminfo | grep HugeAnonHugePages: 106496 kBHugePages_Total: 512HugePages_Free: 504HugePages_Rsvd: 27HugePages_Surp: 0Hugepagesize: 2048 kB

Then add the following to php. ini:

The Code is as follows:


Opcache. huge_code_pages = 1


In this way, PHP uses large memory pages to store its text segments and the huge in memory allocation, reducing TLB miss and thus improving performance.

4. Opcache file cache

Enable Opcache File Cache (experimental). By enabling this, we can allow Opcache to Cache opcode to external files. For some scripts, the performance will be significantly improved.
Add the following to php. ini:

The Code is as follows:


Opcache. file_cache =/tmp


In this way, PHP will Cache some Opcode binary export files under the/tmp directory, which can exist across the PHP lifecycle.

5. PGO

My previous article: Making PHP 7 faster (gcc pgo) has also been introduced, if your PHP is dedicated to a project service, such as just for your Wordpress, or drupal, or something else, then you can try to improve PHP through PGO, specifically for your project to improve performance.

Specifically, we use wordpress 4.1 as the optimization scenario. First, when compiling PHP, we should first:

The Code is as follows:


$ Make prof-gen

Then train PHP using your project, such as for Wordpress:

The Code is as follows:


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


That is, let php-cgi run the wordpress homepage 100 times to generate some profile information during this process.

Finally:

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

At this time, the PHP 7 you compiled is the most high-performance compilation version tailored for your project.

So much for the time being. I will try again later. Please try thanks.

I would like to share with you the five tips for optimizing and improving the performance of PHP7.

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.