| 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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor





