Goal
Diagnose a slow store and know the typical causes on the PHP and database side.
Key concepts
- Tools: Query Monitor, the slow query log, APM (New Relic and similar)
- Cart, checkout and My Account pages aren't fully cached — the backend has to be fast
- Autoloaded options: large values in
wp_optionsload on every request - Object cache (Redis / Memcached) — caches queries and transients between requests
- HPOS, lookup tables, indexes for your own tables
- Growing tables: sessions, Action Scheduler logs, draft orders
Diagram
flowchart TD
S["The page is slow"] --> QM["Query Monitor"]
QM --> Q{"What takes the most?"}
Q -- "SQL queries" --> DB["duplicates, meta_query,<br/>no index"]
Q -- "HTTP requests" --> EXT["API in the page request<br/>→ cache / queue"]
Q -- "PHP" --> PHP["heavy hooks, loops<br/>→ profiler"]
Q -- "autoload" --> OPT["large options<br/>→ autoload = no"]
Code
Find the largest autoloaded options:
SELECT option_name, LENGTH(option_value) AS bytes
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto')
ORDER BY bytes DESC
LIMIT 10;
Cache an external request instead of making it on every page:
<?php
function my_exchange_rate(): float {
$rate = wp_cache_get( 'usd_rate', 'my-plugin' );
if ( false === $rate ) {
$response = wp_remote_get( 'https://api.example.com/rate/usd', [ 'timeout' => 3 ] );
$rate = is_wp_error( $response ) ? 41.0 : (float) wp_remote_retrieve_body( $response );
wp_cache_set( 'usd_rate', $rate, 'my-plugin', HOUR_IN_SECONDS );
}
return $rate;
}
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
| The admin is slow on every page | Megabytes of autoloaded options | Find large options and turn off their autoload |
| Checkout is slow only at peak hours | An external API request in a cart hook | A cache or a background job |
| The Action Scheduler table has millions of rows | Logs and completed jobs are kept too long | Configure retention and cleanup |
Weak and strong answer
Question: The client says "the store is slow". What do you do?
Weak answer. Install a caching plugin and optimize the images.
Strong answer. First, measurements: which pages, for whom (a guest or a customer with a cart), TTFB or the frontend. For the backend — Query Monitor on the slow page: the number and time of SQL queries, HTTP requests, autoload. Then I fix the cause: an index, a cache, a queue instead of a synchronous API. A page cache won't help the cart and checkout — they need a fast backend.
Why the second is stronger: Diagnosis before treatment and an understanding of what a store can and can't cache.
Practice
Turn on Query Monitor on the category, cart and checkout pages. For each, write down the number of queries, the SQL time and the slowest query. In the terminal find the top 10 autoloaded options, turn off autoload for the one that doesn't belong there and run the query again.
Interview Questions
They are personal: the cart, the address, the discounted prices of a specific customer. A page cache would serve one customer another customer's cart. So they are excluded from the cache, and WooCommerce sets cookies that caching plugins and hosts use to bypass the cache for customers.
It keeps query results and transients in memory (Redis, Memcached) between requests. Fewer SQL queries on every page, especially for logged-in users and the cart.
Sessions (woocommerce_sessions), Action Scheduler jobs and logs, order meta, draft orders. They need cleanup and size monitoring.