How to Fix High TTFB on WordPress (LiteSpeed, PHP and MySQL)

Time to first byte (TTFB) is the time between a browser asking for a page and the first byte of HTML coming back. On WordPress it is decided almost entirely on the server: PHP, the database and whether a cache answered. If your TTFB is above 600ms, no image compression or script deferral will get you to good Core Web Vitals, because LCP cannot start before the HTML arrives.

This guide is the order we work in on client servers.

1. Measure from the right places

Test the HTML document only, from more than one region, with and without cache:

# Cached page (what most visitors get)
for i in 1 2 3; do curl -so /dev/null -w '%{time_starttransfer}\n' https://example.com/; done

# Force a cache miss with a unique query string
curl -so /dev/null -w '%{time_starttransfer}\n' "https://example.com/?nocache=$RANDOM"

# Check what answered
curl -sI https://example.com/ | grep -iE 'x-litespeed-cache|cf-cache-status|x-cache|server'

Rule of thumb:

Result Meaning
Cached < 150ms, uncached < 600ms Healthy. Work on the front end.
Cached fast, uncached > 1s PHP or database bottleneck. Logged-in users, carts and admin suffer.
Cached slow too Cache is not being hit, or the network path is the problem (no CDN, far region).

2. Confirm the page cache is actually hitting

On LiteSpeed, x-litespeed-cache: hit is what you want. A miss on every request usually means:

  • A plugin sets a cookie on every visit (often consent, A/B testing or currency switchers), which makes the page private.
  • Query strings such as utm_* or fbclid are not ignored, so every campaign click is a new cache key.
  • The LSCache plugin is active but CacheLookup is off at the server level.

In the LiteSpeed Cache plugin, check Cache → Excludes and Cache → Advanced → Drop Query String (add utm*, fbclid, gclid). On Nginx with FastCGI cache, look at $upstream_cache_status in your access log.

3. Fix the uncached path: PHP

Check the PHP version and OPcache first. PHP 8.2+ with OPcache properly sized is a large free win.

php -v
php -i | grep -E 'opcache.enable|opcache.memory_consumption|opcache.max_accelerated_files'

Sensible OPcache starting values for a server running a few WordPress sites:

opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=60

On LiteSpeed, PHP runs through LSAPI. If requests queue under load, raise PHP_LSAPI_CHILDREN in the external app config, staying within the account’s CloudLinux entry-process and memory limits. On cPanel with CloudLinux, check whether the account is hitting its limits:

lveinfo --period=1d --by-fault=any --display-username | head

Entry-process (EP) or physical-memory faults mean requests are being refused or queued. That shows up as slow TTFB or 508 errors.

4. Fix the uncached path: the database

Two things account for most slow WordPress databases.

Autoloaded options. WordPress loads every autoload = yes row from wp_options on every request.

wp db query "SELECT ROUND(SUM(LENGTH(option_value))/1024) AS autoload_kb FROM wp_options WHERE autoload IN ('yes','on','auto-on','auto');"
wp db query "SELECT option_name, ROUND(LENGTH(option_value)/1024) kb FROM wp_options WHERE autoload IN ('yes','on','auto-on','auto') ORDER BY LENGTH(option_value) DESC LIMIT 15;"

Above roughly 800KB, investigate. Leftovers from deleted plugins and huge transients are common. Set them to not autoload or remove them, after a backup.

No persistent object cache. Without Redis or Memcached, every uncached page repeats the same queries. Install Redis, then the Redis Object Cache plugin (or LSCache’s object cache setting), and confirm it is connected:

redis-cli ping
wp redis status

5. Put a CDN in front for distance

A server in London adds roughly 70–90ms of round trip to New York and 250ms+ to Sydney before PHP does anything. Cloudflare with HTML caching (or LiteSpeed’s QUIC.cloud) serves cached pages from the edge near the visitor. Make sure the CDN respects your cache-control headers and bypasses cache for logged-in and cart cookies.

6. Re-measure

Repeat step 1. Typical results after this process on a reasonably sized server: cached TTFB under 100ms at the edge and uncached under 400ms. Field data in Search Console takes 28 days to fully reflect the change.

Checklist

  • Page cache hit confirmed in response headers
  • Marketing query strings dropped from cache key
  • PHP 8.2+ with OPcache sized
  • No CloudLinux EP/memory faults
  • Autoload under ~800KB
  • Redis object cache connected
  • CDN caching HTML with correct bypass rules