Slow search and admin-ajax: the requests a page cache never sees
A cached page costs almost nothing. These two kinds of request cost a full WordPress load every time.
Where this starts
This is the second half of an incident. A download store was returning 503 for most of every business day, and enabling OPcache took the account from 100/100 CPU to about 15/100. The constant load was gone. The bursts were not. Finding them took the access logs.
Count the requests before you guess
A page cache only helps with requests it is allowed to answer. So the first question is which URLs get the traffic, and which of those can never be cached. One line on the access log answers the first part:
awk '{print $7}' access_log | cut -d'?' -f1 | sort | uniq -c | sort -rn | head -20
And one for search, which WordPress serves from the s parameter:
grep -c '[?&]s=' access_log
On this store the answer was plain. Search requests were roughly 21% of all traffic, arriving from a widely distributed set of IP addresses. And most of the 503s landed on admin-ajax.php.
Why WordPress search is expensive
The default search runs a LIKE '%term%' comparison against post titles and content. A pattern that starts with a wildcard cannot use an index, so MySQL reads every row. Here the posts table held 757,000 rows, and each search occupied a PHP worker for about twenty seconds. Search result URLs are different for every term, so a page cache does not help either.
Twenty seconds per request, at a fifth of all traffic, on an account with a hard CPU ceiling: a few of those in parallel and every worker is busy, and the next visitor gets a 503.
Ask why the table is that large
A store does not have 757,000 products. I traced the row count: 615,750 of those posts were legacy log entries left behind by the Easy Digital Downloads 3.0 migration, with 3.6 million rows of metadata behind them. Legacy logging had stopped in 2022, and the table that replaced it had been running since 2019, which made the old rows safe to purge.
Deleting rows nobody reads made every search cheaper, and every backup smaller. Before you index, cache or rate-limit a slow query, check what it is scanning.
admin-ajax: the request that skips the cache
Every call to admin-ajax.php loads WordPress in full, and a POST request is never served from the page cache. That is fine for the occasional form. It is not fine when a plugin sends one on every page view.
This store had a page-view counter plugin doing exactly that. The page itself came from the cache in a few milliseconds, then the visitor's browser sent a POST that woke WordPress anyway. The cache was working and the server was still doing the full work for every visitor.
Two more things were adding to the same endpoint. The editor heartbeat was firing every 10 seconds for every open admin tab. I raised it to 120 through a must-use plugin:
<?php
// wp-content/mu-plugins/heartbeat.php
add_filter( 'heartbeat_settings', function ( $settings ) {
$settings['interval'] = 120;
return $settings;
} );
And one option written by a security plugin had grown to 33MB. If it is autoloaded, WordPress reads all of it on every request, including every admin-ajax call. It was cleared.
The mistake I made
My first fix for search was to replace the LIKE-based search with an indexed search plugin. On that host it stalled at 6% indexed and returned nothing to users, so I rolled it back. Building an index over 750,000 rows needs CPU, and the machine was already at its ceiling.
What I should have done first is rate-limit search at the CDN edge, so the bursts stop reaching PHP at all, and only then move indexing to a background job or an external service.
A short checklist
- Count requests by path in the access log. Look at search and
admin-ajax.phpfirst. - For each busy path, ask whether the page cache can answer it. If not, it costs a full load.
- Find out which plugin sends the admin-ajax calls. The
actionparameter names it. - Check the size of the table a slow query scans, and why it is that size.
- Rate-limit at the edge before you rebuild anything on a server that is already full.
After these changes, CPU faults fell from between 100 and 183 an hour to near zero outside the search bursts. The whole case is on performance and infrastructure. If your site shows the same pattern and you want it traced, that is what technical consulting is for.
// services/
If this is close to what you need
Tell me what you are trying to build or fix, what already exists, and what a good outcome looks like. I reply within two business days, and I will tell you honestly whether I am the right person.
- Technical consultingA second pair of eyes, and a written answer
- Fractional CTOPart-time technical leadership for a small team
- WordPress and WooCommercePlugins that survive updates and get extended
- Performance and infrastructureSlow, expensive or unstable, traced to the cause
- Integrations and automationSystems that were never meant to talk
- ApplicationsWeb apps, macOS utilities and browser extensions
- Design to working WordPressA finished design, rebuilt natively in Elementor