How to make PHP 7 run faster
Introduction | PHP 7 is much faster than 5.x, even if it is just a simple version upgrade It's already very interesting, but everyone still hopes that it will become faster and faster. At this time, making some small adjustments will make it more futuristic. Let's try it! |
Preparation in advance
When it comes to PHP 7, it must not be able to run LAMP or LEMP. Please prepare the underlying services first. Install.
- [CentOS 7] Integrate Apache, MySQL, and PHP 7 to form a LAMP Server
- [CentOS 7] Integrate Nginx, MariaDB, and PHP 7 to form a LEMP Server
In the past, when we wanted to speed up PHP processing, we usually used it with any one of APC, eAccelerator, and XCache; forget them now, and use OPcache from now on, which is PHP 7 A PHP support module co-developed by Hui Xinchen, one of the developers. This implementation is based on the LEMP architecture, and the package library uses the Remi version. Don’t forget to modify the path and setting values according to your actual environment.
Related learning recommendations: PHP programming from entry to proficiency
Start setting
Installation OPcache suite.
sudo yum -y install php70-php-opcache
Edit the main profile.
sudo vi /etc/opt/remi/php70/php.ini
Add these parameters.
zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1opcache.file_cache=/ home/opcache opcache.huge_code_pages=1
Start Huge Pages, which is a large temporary paging mechanism. For detailed instructions, please refer to The Linux Kernel Archives - Huge Pages, on my machine the test result is changed to 512.
sudo sysctl -w vm.nr_hugepages=512
Create a dedicated directory for OPcache.
sudo mkdir /home/opcache sudo chown nginx:nginx /home/opcache
Restart PHP-FPM and you will see that OPcache has been started.
sudo systemctl restart php70-php-fpm
In addition, we can also install memcached. As the name suggests, it uses memory as a cache to speed up the operation of the system.
sudo yum -y install memcached
Edit the main program file.
sudo vi /etc/sysconfig/memcached
There are not many parameters, please modify them according to your needs.
PORT - 端口,别忘了开防火墙。 MAXCONN - 总连接数。 CACHESIZE - 内存使用量,单位是KB。 PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="1024" OPTIONS=""
Start memcached and let it start automatically after booting.
sudo systemctl restart memcached sudo systemctl enable memcached
Open the firewall
sudo firewall-cmd --permanent --zone=public --add-port=11211/tcp
Then install the memcached for PHP support module.
sudo yum -y install php70-php-pecl-memcached
Restart PHP-FPM.
sudo systemctl restart php70-php-fpm
最后看一下phpinfo(); 函数的显示结果,出现memcached 的段落就代表成功了。
实测结果
这边直接引用对岸的网友的资料,在OneAPM -使用PHP 7给Web应用加速这篇文章里,他测试了Wordpress 4.1.1、Drupal 8、phpBB 3.1.3、MediaWiki 1.24.1、Opencart 2.0.2.0 、WardrobeCMS 1.2.0、Geeklog 2.1.0、Magento 1.9.1.1、Traq 3.5.2、Cachet、Moodle 2.9-dev、ZenCart 1.5.4等12种套件的比较结果。 以Wordpress 4.1.1为例,我们可以看到PHP 7比起5.3 ~ 5.6的读取速度(Read)及延迟时间(Latency)都有大幅改善。
The above is the detailed content of How to make PHP 7 run faster. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to execute .sh file in Linux system? In Linux systems, a .sh file is a file called a Shell script, which is used to execute a series of commands. Executing .sh files is a very common operation. This article will introduce how to execute .sh files in Linux systems and provide specific code examples. Method 1: Use an absolute path to execute a .sh file. To execute a .sh file in a Linux system, you can use an absolute path to specify the location of the file. The following are the specific steps: Open the terminal

PyCharm is a very popular Python integrated development environment (IDE). It provides a wealth of functions and tools to make Python development more efficient and convenient. This article will introduce you to the basic operation methods of PyCharm and provide specific code examples to help readers quickly get started and become proficient in operating the tool. 1. Download and install PyCharm First, we need to go to the PyCharm official website (https://www.jetbrains.com/pyc

In Python, we can use the PyExecJS library or Python’s js2py library to run Javascript code. The PyExecJs library provides a consistent API to run JavaScript code from Python using a variety of JavaScript engines, including Node.js, JavaScriptCore, and Google's V8 engine. The js2py library allows you to execute JavaScript code in Python by parsing the JavaScript code and interpreting it in Python. This article will teach us how to run javasc from Python using the PyExecJS library

Why can't win7 run exe files? When using the Windows7 operating system, many users may encounter a common problem, that is, they cannot run exe files. exe files are common executable files in Windows operating systems. They are usually used to install and run various applications. However, some users may find that when they try to run the exe file, the system does not respond or gives an error message. There are many reasons for this problem. Below are some common causes and corresponding solutions:

Why can't win7 run bat files? Recently, many users using the Windows7 operating system have reported that they cannot run .bat files. This sparked widespread discussion and confusion. Why can't a well-functioning operating system run a simple .bat file? First, we need to understand the background of the .bat file. A .bat file, also known as a batch file, is a plain text file that contains a series of commands that can be used by the Windows command interpreter (cmd.ex

Do you know how to run m files in matlab? Below, the editor will bring you a tutorial on how to run m files in matlab. I hope it will be helpful to you. Let’s learn with the editor! 1. First open the matlab software and select the upper left "Open" the corner, as shown in the picture below. 2. Then select the m file to be run and open it, as shown in the figure below. 3. Press F5 in the window to run the program, as shown in the figure below. 4. We can view the running results in the command line window and workspace, as shown in the figure below. 5. You can also run the file by clicking "Run" directly, as shown in the figure below. 6. Finally, you can view the running results of the m file in the command line window and workspace, as shown in the figure below. The above is the matlab method that the editor brought to you

Regarding Microsoft's new system Windows 10, friends want to know which version of the Windows 10 operating system runs the fastest and smoothest. Version updates are actually updates to system content and functions and repairs to defects. Which version of win10 runs the fastest? 1. The difference between each version of win10 is mainly in their respective functions. 2. Except for different functions, other aspects are the same. 3. There is no big difference between the various versions of win10 in terms of running speed. The main difference is Look at the configuration of your own computer ~ win10 Home Edition: 1. Win10 Home Edition is equivalent to the core version of win8.1, an entry-level system version. 2. The country-specific version of win10 home version is equivalent to the OEM Chinese version of win8.1.

There are three ways to open the Run dialog: using the Win + R shortcut, through the search function, or by typing "Run" directly in the Start screen.
