WordPress station construction process (IV) speed optimization

Because WordPress program focuses on scalability and compatibility, the execution process contains a large number of hooks, judgments, file loading and other operations, will lead to high system resource consumption, slow execution. When the number of visits is small, once the number of visits, WordPress CPU and memory usage is quite high, so WordPress optimization is essential.

PHP Opcache

Opcache’s full name is: Opcode cache, which was born out of Optimizer plus, a closed-source but free-to-use PHP optimization acceleration component developed by Zend, PHP’s official company. Opcode cache is designed to avoid duplicate compilations and reduce CPU and memory overhead.

In PHP 7, Opcache is installed by default and does not require additional installation, but needs to be turned on manually. In the PHP .ini file, please find the “opcache” and turn it on by referring to the following.




Once you’ve turned it on, you’ll see the following in PHPinfo:

WP Super Cache cache plug-in

WP Super Cache is wordPress’ best cache optimization plug-in, and the other W3 Total Cache is similar to it, and while W3 Total Cache is more powerful, it’s enough for a typical website to use WP Super Cache. WP Super Cache is easier to configure than W3 Total Cache.

WP Super Cache’s plug-in home page:https://wordpress.org/plugins/wp-super-cache/

In the WordPress background plug-in – install the plug-in, enter the WP Super Cache keyword to find, you can install the plug-in.

Once the plug-in is installed and enabled, the WP Super Cache option appears in the settings menu in the background, goes to the configuration page, and follows the figure below to set it up.

When Expert Mode is turned on, if it is an Apache environment, WP Super Cache automatically modifies the .htacces file, or modifies the contents of the .htacces file as prompted. In the case of a Nginx environment, you need to replace wordpress’s pseudo-static rules with the following.

rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ .*\.(oft|eot|svg|ttf|woff|woff2)$
	add_header Access-Control-Allow-Origin *; # 解决字体跨站问题
	add_header Access-Control-Allow-Headers X-Requested-With;
	add_header Access-Control-Allow-Methods GET,OPTIONS;
	expires max;
	error_log off;
	access_log /dev/null;
# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.
set $cache_uri $request_uri;
if ($request_method = POST) {
        set $cache_uri 'null cache';
if ($query_string != "") {
        set $cache_uri 'null cache';
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $cache_uri 'null cache';
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'null cache';
# 移动设备支持
# 移动浏览器部分可将其存储为非缓存版本。 默认情况下,由于包括21个在内的大多数现代wordpress主题都具有响应性,因此被评论。 如果要使用WP-Touch之类的插件,请在本节中取消注释配置行
# if ($http_x_wap_profile) {
#        set $cache_uri 'null cache';
#if ($http_profile) {
#        set $cache_uri 'null cache';
#if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
 #       set $cache_uri 'null cache';
#if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
  #      set $cache_uri 'null cache';
#END 移动设备支持
# 使用缓存或实际文件(如果存在),否则将请求传递给WordPress
location / {
        try_files /wp-content/cache/supercache/$http_host/$cache_uri/index-https.html $uri $uri/ /index.php?$args ;}

If https access is not turned on, the last section is replaced with the following code:

location / {
        try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;}

If mobile device support is turned on (non-responsive topic recommendations are turned on, different content is cached on the PC side and mobile side) the line needs to be removed from the Nginx configuration above.

WP Super Cache cache preload configuration:

Autoptimize plug-in

The role of plug-ins is to make your website faster by optimizing CSS, JS, images, Google fonts, etc.

This section is optimized for js code, where the Aggregate JS-files option ticks, which can cause compatibility issues for some topics or plug-ins, remove the check if something goes wrong, or exclude the appropriate js code from the exclusion script.

The CSS optimization section is selected as shown above.

As for the option to inline and postpone CSS, it can be turned on as appropriate (for advanced users only).

Turn on the Memcached object cache

The first step is to install the Memcached server with PHP’s Memcached extension, which is not covered in this article.

LNMP one-click installation package adds Memcached tutorial: https://lnmp.org/faq/addons.html

Install Memcached in the Pagoda panel in the software store.

Once the Memcached server and PHP’s Memcached extension are installed, enter the WordPress background and search for the MemcacheD Is You Friend plug-in to be installed. Github address of the MemcacheD Your Friend plug-in: https://github.com/wpbullet/memcached-is-your-friend.

When you enable the MemcacheD Your Is Friend plug-in, you can see information like this in the background tool, Memcached.

If the IP address and port of the MemcacheD server are not the default, you can add the following at the top of the WP-config .php file ( modified as the actual situation):

$memcached_servers = array(
	'default' => array(

Read on: WordPress Station Building Process (V) SEO Optimization

1 thought on “WordPress station construction process (IV) speed optimization”

Leave a Comment