Blazing Fast Cloud Servers

Server set-up in less than 1 minute, Instant scaling up or down as required, 99.95% uptime guaranteed, No hardware maintenance, Simple backup and monitoring, Unbeatable pricing.

Visit Website

How To Speed Up WordPress With Memcached + Batcache + Cloudflare (The Definitive Guide)

Speed up WordPress

This tutorial shows you how to speed up WordPress with Memcached + Batcache + Cloudflare CDN, also get 100 Score in Google PageSpeed Insights.
Please add your domain name to Cloudflare in advance.
Please resolve your domain name to an IP address in advance.
Demo domain: blogwp.ovh
Please replace blogwp.ovh with your own domain name.
Twenty Twenty-One theme with default demo site
The VPS used in this article: Vultr (1GB RAM, 1 vCore)
LEMP stack used in this article: Webinoly
Operating System: Ubuntu 20.04

https://blogelegant.com/ build with Hostwinds KVM VPS and Nginx FastCGI Cache.
Affiliate Disclosure: This page contains affiliate links. If you click through and purchase an item, I may earn a commission.

When you use Webinoly to install WordPress,the Memcached will been enabled.
You can read this article for a detailed installation of Webinoly

How To Install WordPress with Webinoly (Enable Nginx FastCGI Cache)
This tutorial shows you how to install WordPress with Webinoly (Enable Nginx FastCGI Cache)

1、Quick Setup, install LEMP Stack

wget -qO weby qrok.es/wy && sudo bash weby 3
MySQL has been installed successfully!
phpMyAdmin has been installed successfully!


****************************************************************************
******            INSTALLATION HAS FINISHED SUCCESSFULLY              ******
****************************************************************************
********      Save your DB access password in a secure place:       ********
******      root: 1NBREnyqrGYDvhDX       admin: ITtieEIVki5PzwJQ      ******
****************************************************************************


****************************************************************************
************************     D O N A T I O N S     *************************
***   If you like Webinoly, buy me a coffee or a beer to show support.   ***
****************************************************************************
*************     Bitcoin: 1E3Ybo5UcvaAr1MoK4nBnMRFFY9aEMiku3     **********
*******   GitHub Sponsors: https://github.com/sponsors/QROkes     **********
***************    PayPal: https://www.paypal.me/qrokes     ****************
****************************************************************************
***   Your regular donations is what keep this project moving forward.   ***
****************************************************************************

2、Install WordPress

sudo site blogwp.ovh -wp
[email protected]:~# sudo site blogwp.ovh -wp

Downloading WordPress...


[WARNING] HTTP Authentication Credentials not found and you may need it to complete the WordPress installation process!!
[WARNING] Login for www-data is not enabled and you may need it to upload your site files!
Site blogwp.ovh has been successfully created!

3、Install Object Cache 4 everyone Plugin, it will detects automatically any Memcached server running and adds an object-cache.php file to /wp-content/ directory


I use Webinoly, the Object Cache 4 everyone Plugin will add an object-cache.php to /var/www/blogwp.ovh/htdocs/wp-content

4、Download and unzip Batcache Plugin, Upload advanced-cache.php to the /wp-content/ directory. 
I use Webinoly, the advanced-cache.php should be uploaded to /var/www/blogwp.ovh/htdocs/wp-content


Add define(‘WP_CACHE’, true); to wp-config.php to activate Batcache:

define('WP_REDIS_SELECTIVE_FLUSH', true);
define('WP_CACHE_KEY_SALT', 'wp_blogwp.ovh');
define('WP_CACHE', true);
/* That's all, stop editing! Happy publishing. */

After set up correctly, you will see two drop-ins files.

I use Webinoly, the wp-config.php file location: /var/www/blogwp.ovh

5、Install and activate Batcache Plugin
Memcached is a free & open source, high-performance, distributed memory object caching system. Batcache uses Memcached to store and serve HTML pages.
To determine if a page has been cached, refresh the page, view the source code and the last lines on the page should read something like:

<!--
	generated in 0.025 seconds
	8766 bytes batcached for 300 seconds
-->

The default cache time of Batcache is 300s, which can be adjusted.
edit advanced-cache.php file

Change
var $max_age = 300


to
var $max_age = 3600

Refresh the page, view the source code again and the last lines on the page should read something like:

<!--
	generated in 0.027 seconds
	8767 bytes batcached for 3600 seconds
-->

6、Load test
Load Testing Tool: loader.io
Load Testing Type: Clients per second
6.1 Download the verification file

6.2 Upload the verification file. I use Webinoly, the verification file of loader.io need to be uploaded to /var/www/blogwp.ovh/htdocs

6.3 Click “Verify” button, shows “Congrats, target verification passed!”

Load Test after use Memcached + Batcache
50 clients per second in 1 minute
With Memcached + Batcache, the average response time is 49 ms.


150 clients per second in 1 minute
With Memcached + Batcache, the average response time is 47 ms.


250 clients per second in 1 minute
With Memcached + Batcache, the average response time is 47 ms.


500 clients per second in 1 minute
With Memcached + Batcache, the average response time is 50 ms.


750 clients per second in 1 minute
With Memcached + Batcache, the average response time is 1370 ms.


1000 clients per second in 1 minute
With Memcached + Batcache, the average response time is 2229 ms.

7、Cloudflare CDN Settings:
When you use Cloudflare CDN, by default it only cache the static files like images, CSS, JavaScript etc, it doesn’t cache HTML pages. If you want to make your site faster, you need to use Cloudflare page rule feature to cache HTML pages.

Because blogwp.ovh is a demo site, I didn’t install Let’s Encrypt’s SSL certificates. So when you use Cloudflare SSL, then the SSL/TLS encryption mode should be set to “Flexible”


Click the ‘SSL/TLS’ section, click the Edge Certificates tab, toggle the Always Use HTTPS switch to On.


Click the ‘Speed’ section, click the Optimization tab, turn Auto Minify on, toggle the Brotli switch to On.


Click the ‘Caching’ section, click the Configuration tab. Under Browser Cache TTL section, set the option to Respect Existing Headers.


Click the ‘Network’ section, toggle the HTTP/3 (with QUIC) switch to On, toggle the 0-RTT Connection Resumption switch to On, toggle the gRPC switch to On, toggle the WebSockets switch to On.

The following steps are the most important part: Set up cache everything page rule in Cloudflare, this can greatly speed up your WordPress website.
Note: Set up cache everything page rule can cause several problems, such as the WordPress admin bar will show if the user is logged in. The new comments will not be visible unless you clear the cache. The comment area will caches the WordPress login user name like the image shows.

But don’t worry, the next step is to show you how to solve these problems.

Method: Use CloudFlare Cache Purger for WordPress plugin.


Make sure the ‘Browser Cache TTL’ in the ‘Caching’ section is set to ‘Respect Existing Headers’.
CloudFlare Cache Purger for WordPress Plugin Settings:
1. Enter your E-mail Address and Cloudflare Global API Key
2. Choose which content to be cleared


Note: After setup this plugin, you will need to create “Cache everything” page rule on Cloudflare.
My Cloudflare page rule settings
https://blogwp.ovh/*
Browser Cache TTL: an hour, Cache Level: Cache Everything, Edge Cache TTL: 2 hours
When you correctly set up CloudFlare Cache Purger for WordPress plugin, the above annoying problems will be solved.
More methods
https://blogelegant.com/reduce-cloudflare-ttfb-and-speed-up-wordpress-site/

Load Test after use Memcached + Batcache + Cloudflare Cache Everything
500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 12 ms.


1000 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 12 ms.


2500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 14 ms.


3500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 91 ms.


4000 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 145 ms.


4500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 431 ms.


5000 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 769 ms.


6500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 933 ms.


7500 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 1049 ms.


10000 clients per second in 1 minute
With Memcached + Batcache + Cloudflare Cache Everything, the average response time is 1140 ms.

I use KeyCDN’s performance tool to measure the TTFB
The TTFB before settings


The TTFB after settings

Speed Tests Results
GTmetrix:

PageSpeed Insights:

Sucuri Load Time Tester:

The speed optimization method can be summarized as: Memcached + Batcache + Cloudflare CDN + CloudFlare Cache Purger for WordPress plugin

If you have any questions, please leave me a comment.

Copied title and URL