Home  >  Article  >  Backend Development  >  How to improve MediaWiki website performance through PHP-FPM optimization

How to improve MediaWiki website performance through PHP-FPM optimization

WBOY
WBOYOriginal
2023-10-05 09:32:021189browse

How to improve MediaWiki website performance through PHP-FPM optimization

How to improve the performance of MediaWiki website through PHP-FPM optimization

With the rapid development of the Internet, Wikipedia, as the world's largest wiki knowledge base, has a huge number of website visits huge. In order to meet the growing user needs and improve the response speed of the website, it is crucial for large websites like Wikipedia to optimize and improve website performance.

This article will focus on MediaWiki, the website platform used by Wikipedia, and introduce how to improve website performance by optimizing PHP-FPM. Several aspects will be explained in detail below.

  1. Configuring the process pool of PHP-FPM

PHP-FPM is a PHP FastCGI manager that can manage PHP processes. By properly configuring the process pool of PHP-FPM, the concurrent processing capabilities of the website can be improved.

First, you need to modify the process pool configuration in the php-fpm.conf configuration file. Adjust the following parameters to meet the needs of the website:

pm = dynamic  // 设置进程管理方式为动态管理
pm.max_children = 100  // 设置进程池中允许的最大子进程数量
pm.start_servers = 10  // 设置启动时的初始进程数量
pm.min_spare_servers = 5  // 设置闲置时保持的最小进程数量
pm.max_spare_servers = 20  // 设置闲置时保持的最大进程数量

The settings of the above parameters need to be adjusted according to the actual situation of the website to ensure that the number of processes can adapt to the concurrent access requirements of the website.

  1. Use OPcache to speed up page loading

OPcache is a built-in code caching extension for PHP that can speed up the execution of PHP scripts. By enabling and adjusting OPcache, you can effectively reduce code compilation time and improve website performance.

In the php.ini file, find the following line of configuration:

;opcache.enable=1

Uncomment it and set it to 1 to enable OPcache.

At the same time, adjust the following parameters related to OPcache to adapt to the needs of the website:

opcache.memory_consumption=128  // 设置OPcache使用的内存量(以MB为单位)
opcache.max_accelerated_files=4000  // 设置最大加速的文件数量
opcache.revalidate_freq=60  // 设置多久检查一次脚本文件是否被修改(以秒为单位)

By reasonably adjusting the above parameters, you can improve the performance of OPcache and speed up page loading.

  1. Enable PHP FastCGI caching

PHP FastCGI caching is a technology that caches compiled PHP scripts in the FastCGI process to increase the execution speed of the script.

First, find the following lines of configuration in the php.ini file:

;cgi.fix_pathinfo=1
;cgi.force_redirect=1
;cgi.redirect_status_env=1

Uncomment it and set it as follows:

cgi.fix_pathinfo=0
cgi.force_redirect=0
cgi.redirect_status_env=0

Next, you need to install the configuration A FastCGI cache plug-in, such as nginx's FastCGI cache module.

In the nginx.conf file, add the following configuration:

http {
    ...
    fastcgi_cache_path /path/to/cache/ levels=1:2 keys_zone=cache_zone:10m inactive=10m;
    ...
    server {
        ...
        fastcgi_cache cache_zone;
        fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host$request_uri";
        fastcgi_cache_valid 200 302 10m;
        fastcgi_cache_valid 404 1m;
        ...
    }
}

By setting the FastCGI cache path and related parameters, you can improve the execution speed of PHP scripts and speed up the response speed of the website.

Summary

By optimizing PHP-FPM, the performance of the MediaWiki website can be significantly improved. This article mainly introduces several optimization methods such as configuring the process pool of PHP-FPM, using OPcache to accelerate page loading, and enabling PHP FastCGI caching. I hope it will be helpful to everyone.

Of course, optimizing performance is an ongoing process and needs to be adjusted and optimized based on actual conditions. It is hoped that through the optimization of PHP-FPM, the user experience of the MediaWiki website can be better and the competitiveness of the website can be improved.

The above is the detailed content of How to improve MediaWiki website performance through PHP-FPM optimization. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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