search
HomeBackend DevelopmentPHP7Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance

Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance

PHP7 has been released. As the largest version upgrade and the largest performance upgrade of PHP in 10 years, PHP7 has shown obvious performance improvements in multiple tests. However, in order to make It can exert its maximum performance, but I still have a few things to remind you.


##Recommendation (free): PHP7

PHP7 VS PHP5.6

1. Opcache

Remember to enable it Zend Opcache, because PHP7 is faster even without Opcache enabled than PHP-5.6 with Opcache enabled, so some people did not enable Opcache during the previous testing period. Enabling Opcache is very simple, just add:# in the php.ini configuration file. ##
 zend_extension=opcache.soopcache.enable=1opcache.enable_cli=1"

2. Use a new compilerUse a newer compiler, GCC 4.8 or above is recommended, because only GCC 4.8 or above PHP can Global Register for opline and execute_data support will be enabled, which will bring about a 5% performance improvement (measured from the QPS perspective of Wordpres)

In fact, versions before GCC 4.8 also support it, but we found that there are bugs in its support , so it must be version 4.8 or above to enable this feature.

3. HugePage

My previous article also introduced: Hugepage to make your PHP7 faster, first in the system Turn on HugePages, and then turn on Opcache's huge_code_pages.

Take my CentOS 6.5 as an example, allocate 512 reserved huge page memory through:

 $sudo sysctl vm.nr_hugepages=512

:

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

Then Add:

  opcache.huge_code_pages=1

In this way, PHP will use large memory pages to save its own text segment and huge memory allocation, reducing TLB misses and improving performance.

4. Opcache file cache

Enable Opcache File Cache (experimental). By enabling this, we can let Opcache cache the opcode cache into an external file. For some scripts, there will be obvious problems. Performance improvement.

Add:

 opcache.file_cache=/tmp

to php.ini so that PHP will cache some Opcode binary export files in the /tmp directory, which can exist across the PHP life cycle.

5、PGO

我之前的文章: 让你的PHP7更快(GCC PGO) 也介绍过, 如果你的PHP是专门为一个项目服务, 比如只是为你的Wordpress, 或者drupal, 或者其他什么, 那么你就可以尝试通过PGO, 来提升PHP, 专门为你的这个项目提高性能.

具体的, 以wordpress 4.1为优化场景.. 首先在编译PHP的时候首先:

 $ make prof-gen

然后用你的项目训练PHP, 比如对于Wordpress:

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

也就是让php-cgi跑100遍wordpress的首页, 从而生成一些在这个过程中的profile信息.

最后:

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

这个时候你编译得到的PHP7就是为你的项目量身打造的最高性能的编译版本.

暂时就这么多吧, 以后想起来再加, 欢迎大家尝试, thanks

更多免费推荐:PHP7教程

The above is the detailed content of Introducing several settings for opening Opcache in PHP7 and optimizing PHP7 performance. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.