How to make PHP 7 run faster

coldplay.xixi
Release: 2023-02-17 16:48:01
forward
3355 people have browsed it


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!

How to make PHP 7 run faster


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
Copy after login

How to make PHP 7 run faster

Edit the main profile.

sudo vi /etc/opt/remi/php70/php.ini
Copy after login

How to make PHP 7 run faster

Add these parameters.

zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1opcache.file_cache=/ home/opcache opcache.huge_code_pages=1
Copy after login

How to make PHP 7 run faster

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
Copy after login

How to make PHP 7 run faster

Create a dedicated directory for OPcache.

sudo mkdir /home/opcache sudo chown nginx:nginx /home/opcache
Copy after login

How to make PHP 7 run faster

Restart PHP-FPM and you will see that OPcache has been started.

sudo systemctl restart php70-php-fpm
Copy after login
Copy after login

How to make PHP 7 run faster

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
Copy after login

How to make PHP 7 run faster

Edit the main program file.

sudo vi /etc/sysconfig/memcached
Copy after login

How to make PHP 7 run faster

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=""
Copy after login

How to make PHP 7 run faster

Start memcached and let it start automatically after booting.

sudo systemctl restart memcached sudo systemctl enable memcached
Copy after login

How to make PHP 7 run faster

Open the firewall

sudo firewall-cmd --permanent --zone=public --add-port=11211/tcp
Copy after login

How to make PHP 7 run faster

Then install the memcached for PHP support module.

sudo yum -y install php70-php-pecl-memcached
Copy after login

How to make PHP 7 run faster

Restart PHP-FPM.

sudo systemctl restart php70-php-fpm
Copy after login
Copy after login

How to make PHP 7 run faster

最后看一下phpinfo(); 函数的显示结果,出现memcached 的段落就代表成功了。

How to make PHP 7 run faster

实测结果

这边直接引用对岸的网友的资料,在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)都有大幅改善。

How to make PHP 7 run faster

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!