WordPress Heartbeat API: How to Tame admin-ajax.php CPU Spikes on a VPS

If your WordPress site runs on a small VPS and CPU climbs every time someone opens the editor, the WordPress Heartbeat API is a likely suspect. It polls admin-ajax.php on a short timer, and on a 1 or 2 GB server that steady background traffic adds up fast. You can slow it down, limit where it runs, or turn parts of it off without breaking WordPress. This guide shows how to confirm it is the cause, change the timing safely, and check that CPU use actually drops.

What the WordPress Heartbeat API Actually Does

The WordPress Heartbeat API is a small JavaScript polling system built into WordPress core. When you are logged in and a page that loads the Heartbeat script is open in your browser, it sends a POST request to /wp-admin/admin-ajax.php every 15 seconds by default. WordPress uses those requests for autosave drafts, post-lock warnings when two people edit the same post, and login session checks.

That design works fine on a large server. On a small VPS it is a different story. Every Heartbeat request starts PHP, loads WordPress, and often hits the database. One editor tab is not a problem, but five tabs and two logged-in admins can turn into a request every few seconds, all day. If you run other background jobs on the same server, the load stacks up. That is why it helps to understand how WordPress cron compares with a real system cron before you blame one feature alone.

How to Tell If admin-ajax.php Is the Problem

Do not change settings on a guess. Confirm the pattern first, because admin-ajax.php CPU spikes can also come from a plugin, a brute-force attempt, or a broken cron job.

Start with the access log. Look for repeated POST requests to /wp-admin/admin-ajax.php, spaced about 15 seconds apart. A quick check looks like this:

grep "POST /wp-admin/admin-ajax.php" /var/log/nginx/access.log | tail -20
grep "admin-ajax.php" /var/log/nginx/access.log | wc -l

Then run htop while an editor tab is open, close the tab, and watch again. If PHP-FPM worker CPU drops within a minute, Heartbeat traffic is a strong candidate. If CPU stays high with no tab open, look elsewhere first. Our walkthrough on finding which process is eating your VPS resources covers the same check for memory, and the method works for CPU too.

Check the timing too. Heartbeat requests arrive on a regular beat, roughly every 15 seconds per open tab, while plugin or attack traffic is usually irregular or much faster. If admin-ajax.php takes seconds to answer, a plugin hooked into the Heartbeat may be doing heavy work on each tick, and slowing the interval alone will not fix it. Also count logged-in users: three staff members with the editor open all day can generate hundreds of extra PHP requests per hour.

Why Small VPS Servers Feel It First

A 1 GB or 2 GB VPS often runs one or two PHP-FPM workers per site, and each Heartbeat request occupies a worker for a short time. With the default 15-second interval, one open editor tab makes about 240 requests per hour, and four tabs make close to 1,000. Those requests compete with real visitors for the same workers, CPU, and database connections.

Shared hosting hides this because the host spreads the load across many servers and often limits what you can see. On your own VPS you see the full cost, and you also control the fix. The same logic applies to other background PHP work. If PHP-FPM is already tight, read our guide on tuning PHP-FPM pool settings for a 2 GB VPS alongside this one, because Heartbeat tuning and pool tuning solve different halves of the same problem.

Slow Down the WordPress Heartbeat API Without Breaking the Editor

The safest first change is to lengthen the WordPress Heartbeat API interval. You keep autosave and post locking, but the requests arrive less often. A 60-second interval cuts Heartbeat traffic to a quarter of the default, and most editors never notice the difference. Add this to a child theme or a small custom plugin, not a parent theme, because a theme update will wipe the change.

add_filter( 'heartbeat_settings', function( $settings ) {
    $settings['interval'] = 60;
    return $settings;
} );

Sixty seconds is a good starting point for most small sites. If two people often edit the same posts, do not go higher, because post-lock warnings arrive slower. If you edit alone, 120 seconds is reasonable. Test the change for a day and watch the access log count for admin-ajax.php fall.

Do not set the interval to an extreme value like 900 seconds and expect autosave to still protect you. A long gap means a browser crash can lose more work. The goal is to reduce admin-ajax.php requests, not to remove the safety net entirely.

Disable the Heartbeat API on the Frontend Only

Most sites do not need Heartbeat on the public frontend at all. The editor and the admin dashboard use it, but a logged-in visitor browsing the front of the site usually gains nothing from a 15-second poll. If you want to disable WordPress Heartbeat API traffic on the frontend while keeping it in wp-admin, add this filter:

add_action( 'init', function() {
    if ( ! is_admin() ) {
        wp_deregister_script( 'heartbeat' );
    }
} );

This is a low-risk change for blogs, business sites, and WooCommerce stores where customers are not editing content on the frontend. If you use a frontend editor or page builder, test it first: if it relies on Heartbeat for autosave, keep Heartbeat on for those pages.

If the dashboard itself feels slow, the cause may sit elsewhere. Our guide on speeding up a slow WordPress admin dashboard walks through the other common culprits, from transients to slow queries, so you can rule them out one by one.

When to Turn It Off Completely (and When Not To)

Some site owners turn Heartbeat off everywhere with a plugin or a filter. That can work on a simple brochure site with one editor who saves often and does not share posts with anyone else. For most sites it trades a small CPU saving for a real loss: no autosave, no warning when someone else opens the same post, and no login expiry check.

Keep Heartbeat on in wp-admin if more than one person edits content, if you write long posts in the browser, or if you have ever lost a draft to a crash. Turn it off completely only when you have a different autosave habit, such as writing in a desktop editor and pasting finished text into WordPress, and you accept the risk.

If you do turn it off, use a maintained plugin or a clear filter rather than editing core files. Core edits vanish on the next WordPress update and leave you thinking the feature is off when it is back on.

Check Your Work: CPU Before and After

A tuning change without a before-and-after check is a guess. Before you change anything, note three numbers: the count of admin-ajax.php POST requests per hour in the access log, the average PHP-FPM CPU use in htop during a normal editing session, and the load average from uptime. Write them down with the time of day.

After you change the interval, wait at least an hour of normal editing, then take the same three numbers again. You should see the request count fall in proportion to the interval change. A move from 15 to 60 seconds should cut Heartbeat requests by about three quarters. CPU use should fall too, though not always by the same ratio, because each request still costs about the same amount of work.

If the request count falls but CPU stays high, the per-request cost is the problem, not the frequency. That points to a plugin doing heavy work inside each Heartbeat tick, or to a database that needs attention. Clean up old revisions and expired transients, then retest. Our guide on cleaning up WordPress revisions and transients covers that cleanup step by step. If the request count does not fall at all, your change is not loading: check that the code sits in an active child theme or plugin and that no other plugin overrides the interval back to 15 seconds.

Heartbeat tuning is a small job with a clear payoff on a small VPS. Confirm the pattern in the logs, lengthen the interval to 60 seconds, turn it off on the frontend where it is not needed, and measure the result. Your editor keeps autosave and post locking, and your server has room for the traffic that actually matters.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.