Fix WordPress High CPU From admin-ajax & wp-cron
Stop 100% WordPress high CPU spikes from admin-ajax.php Heartbeat polling, wp-cron stampedes, xmlrpc.php, and uncached bots.

- When htop shows PHP-FPM pegging all cores at 100%, guessing blindly wastes hours—a 15-second access-log frequency tally immediately reveals whether the culprit is
admin-ajax.php,wp-cron.php,xmlrpc.php, or query-string cache busting. - Deregistering
heartbeatnaively throws fatal JavaScriptTypeErrorcrashes in plugins expectingwindow.wp.heartbeat; KadiCache injects a safe no-op JS stub while preserving post-lock protection inside the Gutenberg/Classic post editor. - Moving
wp-cron.phpout of visitor HTTP loopback requests into aflock-guarded 1-minute system crontab eliminates lock contention during traffic spikes.
Table of Contents (10 sections)
- Step 1: Run This 15-Second SSH Triage Before Changing Anything
- Enabling the PHP-FPM slowlog When Access Logs Look Quiet
- Culprit 1: The WordPress Heartbeat API Multiplication Effect
- Why KadiCache's HeartbeatControl.php Injects a Safe Stub Instead of Blind Deregistration
- Culprit 2: Replacing wp-cron.php Loopback Storms With flock System Cron
- Culprit 3: Query-String Cache Busting, Thundering Herds & Preload Locks
- Culprit 4: Blocking xmlrpc.php, /?s= Search Spam & Runaway AI Crawlers
- 5-Minute Post-Remediation Verification
- Right-Sizing PHP-FPM pm.max_children So CPU Spikes Never Trigger OOM Kills
- Stopping Uncached Internal Search Spam (/?s=...) at the Edge
Diagnosing WordPress high CPU emergencies starts with one rule: read your access log before upgrading your VPS. Over 90% of 100% CPU incidents on WordPress and WooCommerce servers come from four repeatable loops: /wp-admin/admin-ajax.php polling, /wp-cron.php loopback storms, uncached query-string floods, and /xmlrpc.php brute-force bursts.
Step 1: Run This 15-Second SSH Triage Before Changing Anything#
Open an SSH session during (or right after) a CPU spike and run these four read-only commands to pinpoint the exact URI, IP address, or PHP function burning your cores:
# 1. Top 15 most-requested WordPress endpoints (stripping query strings)
tail -n 20000 /var/log/nginx/access.log | awk '{print $7}' | cut -d'?' -f1 | sort | uniq -c | sort -rn | head -15
# 2. Top 15 full URIs WITH query strings (exposes ?wc-ajax=, ?fbclid=, ?s= search spam)
tail -n 20000 /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -15
# 3. Top 10 User-Agents hitting uncached endpoints (exposes runaway AI/SEO crawlers)
tail -n 20000 /var/log/nginx/access.log | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn | head -10
# 4. Check PHP-FPM worker memory footprint and active process states
ps -ylC php-fpm8.3 --sort:rss | tail -n 15Match your top result against this diagnostic matrix before flipping any switch:
| Top Endpoint in Access Log | Typical Spike Rate | Underlying Root Cause | Permanent Engineering Fix |
|---|---|---|---|
/wp-admin/admin-ajax.php | 40 – 350 POST/min | Idle staff browser tabs firing action=heartbeat, or front-end AJAX counters/popups | 3-zone Heartbeat control (HeartbeatControl.php) + audit front-end AJAX |
/wp-cron.php | Overlapping bursts on page hits | HTTP loopback pseudo-cron colliding with long WooCommerce / Action Scheduler jobs | DISABLE_WP_CRON in wp-config.php + flock system crontab |
/?fbclid=... or /?s=... | 150 – 3,000 GET/min | Uncached ad query strings, internal search spam (/?s=), or AI scraper bots | Early Drop-In marketing param ignore + Cloudflare WAF / Bot rules |
/xmlrpc.php | 300 – 8,000 POST/min | system.multicall brute-force bots booting full WordPress per POST | Block /xmlrpc.php at Nginx/Cloudflare + KadiCache Bloat Removal |
Enabling the PHP-FPM slowlog When Access Logs Look Quiet#
What if request volume is low (only 8 requests/minute), yet 4 php-fpm children sit at 99% CPU for 25 seconds each? That points to a hung outbound wp_remote_get() HTTP call without a timeout or an unindexed wp_postmeta LIKE '%value%' SQL scan. Enable request_slowlog_timeout = 5s and slowlog = /var/log/php8.3-fpm.slow.log in your PHP-FPM pool config for ten minutes: PHP will dump the exact file and line number of the offending plugin stack trace.
Culprit 1: The WordPress Heartbeat API Multiplication Effect#
A single logged-in browser tab polling /wp-admin/admin-ajax.php (action=heartbeat) once every 60 seconds looks harmless on staging. Now do the production math for a real WooCommerce store or editorial newsroom: 7 team members keep 8 WordPress tabs open each across dual monitors (Orders, Products, Coupons, Media Library, Analytics, Post Editor) = 56 open browser tabs.
At 15-second intervals, those 56 background tabs generate 224 uncached POST requests per minute—13,440 full WordPress + MySQL bootstraps every single hour! Because admin-ajax.php is an authenticated POST inside /wp-admin/, no page cache or CDN can cache it. Even worse, certain page builders, social-proof popups, and auction plugins enqueue heartbeat.min.js on the public frontend for every anonymous visitor.
Why KadiCache's HeartbeatControl.php Injects a Safe Stub Instead of Blind Deregistration#
Paste a naive wp_deregister_script('heartbeat') snippet from a blog post into functions.php and two ugly regressions surface within 24 hours:
- Lost Editor Post Locks & Autosaves: Inside
post.php(Gutenberg and Classic Editor), WordPress relies on Heartbeat to refresh_edit_lock(wp_check_post_lock()) and autosave drafts. Killing Heartbeat inside the editor lets two writers silently overwrite each other's articles.
- Broken
$depsChains &TypeErrorCrashes: Admin plugins that declare['jquery', 'heartbeat']inwp_enqueue_script()either fail to load at all or crash withUncaught TypeError: Cannot read properties of undefined (reading 'connectNow')when callingwindow.wp.heartbeat.
Look at how Optimization/HeartbeatControl.php in KadiCache Free Core eliminates both failure modes:
- Three Independent Zones (
frontend,admin,editor):HeartbeatControl::context()detectsget_current_screen()->base === 'post'(and even re-localizesheartbeatSettingsoncurrent_screenif WordPress core localizedheartbeatearly duringadmin_init). You can set Frontend = Off, Admin Dashboard = Off or Reduce (60s), and Post Editor = Reduce (60s)—cuttingadmin-ajax.phpHeartbeat traffic by 80%–95% without sacrificing editor safety.
- Dependency Graph Rewiring + Inline Compatibility Shim: Whenever Heartbeat is turned
offonfrontendoradmin,HeartbeatControl::disable()walks$scripts->queue, removes'heartbeat'from dependent$item->deps(preserving'jquery'), and prepends a tiny no-opwindow.wp.heartbeatstub (connectNow,interval,enqueue,isQueued,getQueuedItem) so dependent scripts execute cleanly with zero console errors.
Culprit 2: Replacing wp-cron.php Loopback Storms With flock System Cron#
WordPress's default pseudo-cron (wp-includes/cron.php) fires inside visitor page requests: whenever scheduled timestamps are due, WordPress opens an internal HTTP/HTTPS socket back to https://example.com/wp-cron.php?doing_wp_cron=<microtime>.
On busy WooCommerce stores, pseudo-cron triggers WordPress high CPU in two opposite ways:
- During Uncached Bursts: Twenty concurrent bots hit uncached URLs at
12:00:01while WooCommerce Subscriptions, Action Scheduler, and sitemap rebuilds are due—spawning multiple overlapping loopbackphp-fpmprocesses that compete for PHP-FPM slots andwp_optionscronrow updates.
- After Enabling Page Caching: Once Early Delivery serves 98% of anonymous traffic from
advanced-cache.phpbefore WordPress boots,wp-cron.phpstops receiving regular visitor triggers. Then one editor logs in and inadvertently triggers 400 overdue tasks in a single spike!
Decouple background scheduling from web traffic permanently in two steps:
// Step 1: Add to wp-config.php (above "That's all, stop editing!")
define('DISABLE_WP_CRON', true);# Step 2: Run due cron events every minute via OS crontab with flock mutual exclusion
* * * * * /usr/bin/flock -n /tmp/wp-cron-site1.lock /usr/local/bin/wp cron event run --due-now --path=/var/www/html >/dev/null 2>&1Why use /usr/bin/flock -n + wp cron event run --due-now instead of wget -q -O - https://example.com/wp-cron.php? Three reasons:
- Zero Web Pool Starvation: CLI PHP runs outside
php-fpm'spm.max_childrenlimit and ignores Nginx60sfastcgi_read_timeoutceilings.
- Guaranteed Single-Instance Lock: If a heavy WooCommerce Action Scheduler batch takes 95 seconds,
flock -nskips the12:01overlapping spawn cleanly instead of piling up duplicate workers.
- Instant Visibility: You can inspect slow hooks anytime via
wp cron event listwithout guessing.
Culprit 3: Query-String Cache Busting, Thundering Herds & Preload Locks#
Even after fixing Heartbeat and wp-cron, external traffic spikes can still hammer PHP-FPM if your cache policy leaves three doors open:
- Ad-Campaign Query Strings (
?fbclid=,?gclid=,?msclkid=,?ttclid=,?utm_*): Every click from Facebook, Instagram, Google Ads, or TikTok appends a unique click identifier. InsideCache/Delivery/Early/EarlyRequestServer.php, KadiCache strips marketing tracking parameters from the internal cache key while keeping the full URL intact in the visitor's browser so GA4 and Meta Pixel attribution still record 100% accurately—serving all 10,000 ad clicks from a single4.4 msEarly HTMLHIT.
- Post-Publish Cache Stampedes (60-Second Soft Purge): Deleting cached files immediately when an editor updates the homepage on a busy news site sends 50 simultaneous readers straight into MySQL. KadiCache serves a nonce-verified
STALEsnapshot for up to 60 seconds (NonceDetector.php) while a single background worker regenerates fresh HTML.
- Serialized Warmup Pacing (
Preload/PreloadWorkerLock.php): Never let a cache preloader DDOS your own 2-vCPU VPS. KadiCache enforces strict single-worker locking and paced loopback requests so background warmup yields gracefully to live traffic.
Culprit 4: Blocking xmlrpc.php, /?s= Search Spam & Runaway AI Crawlers#
Finally, inspect whether bots are bypassing your cache intentionally:
- Disable
xmlrpc.php(Optimization/WordPressCleanup.php+ Edge Rule): Attackers lovePOST /xmlrpc.phpbecause a singlesystem.multicallpayload tests 500 passwords inside one PHP execution. Strip RSD/XML-RPC headers inWP Admin -> KadiCache -> Bloat Removaland return403at Nginx or Cloudflare WAF unless you actively use the Jetpack bridge.
- Tame AI & SEO Crawler Floods: Inside
WP Admin -> KadiCache -> Cloudflare -> Security & AI Bots(see our Cloudflare 5-Tab guide), toggle AI Bots Protection and WordPress WAF Rules so unthrottled scrapers are blocked at Cloudflare's edge before touching your origin.
5-Minute Post-Remediation Verification#
Re-run your SSH checks five minutes after applying these fixes:
- Confirm
grep "admin-ajax.php" /var/log/nginx/access.log | tail -n 100drops by 80%–95%.
- Confirm
curl -sI "https://example.com/?fbclid=IwAR12345&utm_source=ig"returnsX-KadiCache: HITandServer-Timing: kc;desc="early_hit".
- Confirm
htopload average settles below0.4 × vCPU countwith zerowp-cron.phploopback spikes.
Right-Sizing PHP-FPM pm.max_children So CPU Spikes Never Trigger OOM Kills#
Even after taming admin-ajax.php, wp-cron.php, and bot floods, misconfigured PHP-FPM process pools routinely turn a brief traffic burst into a total server freeze (Out of Memory kernel killer terminating mysqld!).
Calculate your server's true safe pm.max_children ceiling using real resident memory (RSS) rather than guesswork:
# Measure average resident RAM (in MB) per active php-fpm worker on your server
ps --no-headers -o "rss,cmd" -C php-fpm8.3 | awk '{ sum+=$1 } END { printf ("Avg Worker RAM: %d MB\n", sum/NR/1024) }'Use this formula to size /etc/php/8.3/fpm/pool.d/www.conf cleanly:
Safe pm.max_children = (Total Server RAM - OS Reserve - MySQL Buffer Pool - Valkey RAM) ÷ Avg PHP Worker RAM
| VPS Tier | Total RAM | Reserved for OS + MySQL + Valkey | Remaining for PHP-FPM | Avg WooCommerce Worker (85 MB) | Safe pm.max_children | Recommended pm Mode |
|---|---|---|---|---|---|---|
| 2 GB VPS (1–2 vCPU) | 2,048 MB | 1,100 MB | 948 MB | ~85 MB | 10 – 11 | dynamic or ondemand |
| 4 GB VPS (2 vCPU) | 4,096 MB | 1,850 MB | 2,246 MB | ~85 MB | 24 – 26 | dynamic |
| 8 GB VPS (4 vCPU) | 8,192 MB | 3,400 MB | 4,792 MB | ~90 MB | 50 – 52 | dynamic or static |
| 16 GB Dedicated (8 vCPU) | 16,384 MB | 6,400 MB | 9,984 MB | ~95 MB | 100 – 105 | static |
Why does pairing a right-sized PHP-FPM pool with KadiCache's Early PHP Drop-In transform server stability? Because an Early Cache HIT inside advanced-cache.php finishes in 4.4 ms using < 4 MB of memory instead of holding an 85 MB WooCommerce worker for 450 ms. That single 100x reduction in worker occupancy allows a modest 4 GB VPS (25 PHP-FPM children) to absorb 3,500+ requests per second without breaking a sweat.
Stopping Uncached Internal Search Spam (/?s=...) at the Edge#
One final sneaky WordPress high CPU vector deserves special mention: automated SEO spam bots requesting millions of random internal search URLs (/?s=cheap+crypto+... or /search/random-phrase/). Because WordPress marks is_search() non-cacheable or runs unindexed LIKE '%term%' full-table scans across wp_posts.post_content, 60 search requests per minute can peg MySQL CPU at 100%.
Apply two layers of defense immediately:
- Cloudflare Rate Limiting / Challenge Rule: Challenge or rate-limit requests matching
(http.request.uri.query contains "s=")or(http.request.uri.path contains "/search/")exceeding 10 requests per minute per IP.
- Persistent Object Cache (
ObjectCacheEngine.php): Ensure KadiCache Object Cache is active so repeated option, taxonomy, and widget queries surrounding search templates resolve from RAM in sub-millisecond time.
Frequently Asked Engineering Questions
If I turn Heartbeat completely off in WP Admin, will two editors overwrite each other posts?
Why does wp-cron.php cause high CPU even when human traffic is moderate?
Why do ad clicks (?fbclid, ?gclid, ?utm_source) sometimes spike origin CPU to 100%?
Can aggressive cache preloading itself cause 100% CPU on small 1-vCPU or 2-vCPU VPS servers?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.
12 surgical WordPress head/script bloat toggles, 3-zone Heartbeat control, and safe DB sweeps.
Configure Frontend, Admin Dashboard, and Post Editor Heartbeat intervals safely.
Intercept repeat GET spikes in 4.4 ms with marketing query-string normalization and soft purge.
Reduce server and client execution bottlenecks across WordPress templates.