How To Use Nginx FastCGI Cache (RunCache) To Speed Up Your WordPress Performance

It is no secret that Nginx FastCGI Cache can drastically increase your WordPress performance by improving server response time and reducing the load on PHP-FPM and MySQL/MariaDB server.

Nginx FastCGI Cache is usually an advanced topic for developer experts or sysadmins who are familiar with linux commands and the Nginx config.

In this post, we will enlighten everyone from beginner to expert for this topic, and make Nginx FastCGI Cache (RunCache) as one of your top favourite features in RunCloud.

What is Nginx FastCGI Cache

Before we talk about Nginx FastCGI Cache, let’s talk about how your website works.

  1. When a user visits your WordPress page, the web browser sends an HTTP/HTTPS request to Nginx.
  2. Nginx passes the request to PHP-FPM and Nginx will catch any PHP codes when trying to grabbing the page.
  3. PHP-FPM processes the page and runs through the MariaDB/MySQL database query to retrieve the page.
  4. PHP-FPM sends the generated “static” HTML page back to Nginx.
  5. Nginx send the generated HTML page to the web browser for the user.

When using Nginx FastCGI, this built-in Nginx module will be in between Nginx and PHP-FPM and it is able to generate a cached HTML page from PHP-FPM.

When another user visits the same WordPress page, your website will not perform the same PHP and database requests again because the page is already cached and served by FastCGI.

As a result, your server response time will be much faster after the initial load.

Your PHP-FPM and MariaDB/MySQL load will be reduced.

Your server CPU resource usage will be lower.

And finally, your server can handle more traffic with the same server specifications when using Nginx FastCGI Cache, ultimately allowing you to keep a more affordable server without having to scale any further.

Nginx FastCGI Cache vs Varnish Cache

When talking about server-side caching mechanism, Varnish is also one of the top popular choices.

Unfortunately, Varnish is designed to accelerate HTTP and doesn’t support the HTTPS protocol.

After Let’s Encrypt provides a free SSL/TLS for everyone and Google encourages HTTPS Everywhere and made the move to boost search engine rankings for sites using HTTPS URLS, most websites use HTTPS now for their website to ensure safety from online threats.

There is a workaround to use Varnish with HTTPS, by adding an SSL/TLS terminator in front of Varnish to convert HTTPS to HTTP.

Nginx FastCGI does support HTTPS protocol, which is an excellent alternative to Varnish, without having to increase any complexity in the server.

Nginx FastCGI Cache (RunCache) vs WordPress Cache Plugins

Many WordPress users ask the same question, which one is better?

Actually, both are good for your WordPress website.

When using regular shared hosting, Nginx FastCGI is not available and the only option available is the WordPress cache plugin.

You will need a VPS / Dedicated server to allow you to optimize your WordPress site using Nginx FastCGI Cache.

With proper setup, Nginx FastCGI Cache can perform better than any WordPress cache plugin.

Who Need Nginx FastCGI Cache (RunCache) For WordPress

All WordPress pages can gain huge benefits when using Nginx FastCGI Cache (RunCache).

For blogs, magazines, news, company profile websites, and all types of “static” WordPress sites, all WordPress pages can be fully cached and served faster, excluding WordPress admin pages, which are not cached for obvious for reasons.

For e-commerce, membership, forum, and all types of “dynamic” WordPress sites, most WordPress pages can be fully cached and served faster, except some pages those should stay dynamic.

For example, in the case of WooCommerce, the homepage, shop page, and single product page can be fully cached, but cart, checkout, and my account pages should be excluded. For these dynamic pages, you can use Redis Object Cache to reduce your MySQL database load and make your dynamic pages load faster, but you do not want to cache these pages fully as the latest changes will not be seen

Nginx FastCGI Cache (RunCache) + Redis Object Cache

How To Install Nginx FastCGI Cache (RunCache) Using RunCloud Hub

RunCloud Hub is a hub for all RunCloud plugins for WordPress. It is not only for Nginx FastCGI Cache (RunCache), but also Redis Object Cache and Server Health & Transfer Stats monitoring directly from your WordPress dashboard.

If you want to use Nginx FastCGI Cache (RunCache) to speed up your WordPress website, then RunCloud Hub is the perfect choice for you.

You can read the complete guide on how to install RunCloud Hub here.

Once you have installed the RunCloud Hub plugin, Nginx FastCGI Cache (RunCache) is automatically installed and enabled in your WordPress website, no complex process required.

How To Check If Nginx FastCGI Cache (RunCache) Works

When using any cache WordPress plugin, usually you can check if your WordPress page has been cached by checking the footprint at the end of your web page source code.

Nginx FastCGI Cache (RunCache) works on the server-side, which means there is no footprint on your web page,  you need to check the headers of your website to see these possible values of x-runcloud-cache.

  • HIT : Page is cached and served from the cache.
  • MISS : Page is served dynamically from the server, not from the cache. The response might then have been cached. Refreshing this page again should change the header from MISS to HIT or BYPASS.
  • BYPASS : Page is served dynamically from the server, not from the cache. It is excluded from cache, for example WordPress dashboard admin pages or WooCommerce cart/checkout pages.
  • STALE : Page is served from the cache in cache directory.
  • EXPIRED : Cache is expired. Page is served dynamically from server.

There are many ways to check the headers of your website, for example:

Check HTTP Headers With KeyCDN Performance Test

KeyCDN Performance Test is a free online web performance test to test your website from 10+ test location, from United States to Asia areas.

You can use this tools to evaluate TTFB (Time to first byte) of your website from many locations.

Using this tool, you can also check the response header to see if this web page is served by Nginx FastCGI Cache (RunCache).

Check HTTP Headers With Google Chrome

You can also view the response HTTP headers in Google Chrome by following these steps:

  1. In Chrome, visit your web page, and open Web Developer Tools by pressing F12 or right click and select Inspect.
  2. When opened, click and select the “Network” tab.
  3. Refresh the page to get fresh page data.
  4. Select the top HTTP request on the left panel and observe HTTP headers on the right panel.

Check HTTP Headers With cURL

If you are familiar with linux command, you can use cURL to check HTTP headers quickly.

curl -I http://yourdomain

Performance Benchmark : Handling More Traffics

By eliminating PHP-FPM and MariaDB/MySQL when serving your WordPress page from Nginx FastCGI Cache, the huge benefit is your server can handle more traffics with the same server specifications.

For this test, we use DigitalOcean 1GB RAM ($5) and default WordPress installation using Twenty Nineteen WordPress Theme.

We use two different tools:

  • Loader.io – load testing
  • New Relic Infrastucture – CPU usage monitoring

First Test – 25 users per second in 1 minute

Without Nginx FastCGI Cache (RunCache), average response time is 201 ms.

With Nginx FastCGI Cache (RunCache), average response time is only 9 ms. It is big improvement!

Without Nginx FastCGI Cache (RunCache), the CPU usage jump to 50%.

With Nginx FastCGI Cache (RunCache), the CPU usage is very low.

Second Test – from 0 to 100 users in 1 minute

For this test we use Loader.io to send from 0 concurrent user and increasing to 100 concurrent users within 1 minute.

Without Nginx FastCGI Cache (RunCache), average response time is 1071 ms. You can see that as concurrent users increase, the response time increase also.  Your website will be slow when you have more visitors.

With Nginx FastCGI Cache (RunCache), the average response time is still low, 14 ms, increasing visitors from 0 to 100 users doesn’t affect too much on the response time.

Exploring RunCache Features

Using RunCloud Hub WordPress plugin, you will have more controls on how Nginx FastCGI Cache (RunCache) works in your WordPress website.

RunCache Purger

Purger settings allow you to have more control when the cache is cleared, for example:

  • Automatically clean cache of homepage when post is edited or has a new post.
  • Automatically clean cache of homepage when post removed.
  • Automatically clean cache of post/page/CPT when published.
  • Automatically clean cache of post/page/CPT when comment approved and published.
  • Automatically clean cache of post/page/CPT when comment removed.

RunCache Rules / Exclusion

Rules settings allow you to control Cache Exclusion.

Exclude URL Path option allows you to exclude cache based on matching URL Path. This is very useful when you have dynamic pages that should not be cached in your website.

For example, in WooCommerce, you have the Cart, Checkout, and My Account page that must never be cached. For WooCommerce users, no action needed, these pages have been added by default.

Exclude Cookie option allows you to exclude cache based on matching Cookie name.

Exclude Browser option allows you to exclude cache based on matching Browser User-Agent.

Exclude Visitor IP option allows you to exclude cache based on matching Visitor IP Address.

RunCache also has dedicated settings for query strings, because query strings will not cache by default.

Allow Cache Query String option make it possible for you to allow cache based on matching query string, for example UTM parameters (utm_source, utm_medium, utm_campaign), fbclid, gclid, etc.

Exclude Cache Query String option allows you to exclude cache based on matching Query string.

RunCache Preload

Preload settings allow you to generate caches of your pages without having to wait for a user to visit your pages. Normally, cache is generated after a user visits a page.

You have the options to:

  • Preload caches automatically when any purge action was triggered.
  • Preload caches automatically based on schedule time (day/week/month).
  • Preload caches manually by clicking “Run Cache Preload” link.

If you have big number of posts / pages / products in your WordPress sites, cache preload process somestimes can consume your server CPU resources. It is better to run cache preload manually for this case.

Is It Compatible With Popular WordPress Cache / Optimization Plugins?

Short answer, YES!

The important thing to understand, Nginx FastCGI Cache (RunCache) works on the server level and popular WordPress cache / optimization plugins work on the WordPress/application level.

They are in different spaces and it should be compatible.

When you use both page caching feature from RunCache and your favourite cache plugin, it is possible if Nginx FastCGI Cache (RunCache) stores the caches from generated caches of the cache plugin, it doubles the page cache.

You can choose to disable the page cache feature from your WordPress cache / optimization plugins if you find any issue with RunCache.

For page cache use cases, RunCache should be faster because once your website page cache is available, it will be served to your visitor directly from your server without WordPress.

If you do not want to use any cache plugin and fully use RunCache, you can still use any optimization plugin, for example Autoptimize, to minify HTML, CSS, and Javascript files in your website.

Summary

In RunCloud, we provide you with full control over your server. That is why we do not apply any server-side caching mechanisms automatically to your server.

If you want to apply server-side caching to one of your web applications within your server, then RunCache (RunCloud Hub) is your answer.

RunCache allow you to utilize Nginx FastCGI Cache to speed up your WordPress performance without having to deal with linux command to setup Nginx FastCGI Cache.

All paid plan users (Basic, Pro, Business) can enjoy the full functionality of this feature.

It has been a largely requested feature that we knew would be useful to you and we are very excited to bring this feature to RunCloud. Never ever hesitate to suggest new features that you want to see, and we will make it happen.

Categories: WordPress, Features, Tutorials, Updates

Simplifying Server Management

RunCloud is a cloud server management tool that allows you to maintain full control of your server and host multiple WordPress, WooCommerce, Laravel, and PHP applications with fast and easy configuration.

Start Your Free Trial

5 days free trial no credit card required cancel anytime

2 thoughts on “How To Use Nginx FastCGI Cache (RunCache) To Speed Up Your WordPress Performance

Leave a Comment

Your email address will not be published. Required fields are marked *