Introduction
Have you ever noticed your WordPress admin dashboard feeling sluggish, or perhaps your hosting provider has sent you a warning about high CPU usage? One of the most common, yet often overlooked, culprits behind these performance bottlenecks is the WordPress Heartbeat API. While it sounds vital—and in many ways, it is—an unmanaged Heartbeat can act like a constant drumbeat that eventually wears down your server's resources.
In this guide, we will dive deep into what the Heartbeat API does, why it can become a problem for your server load, and how you can take control of it using both lightweight code snippets and user-friendly plugins. At XeroWP, we believe in lean, high-performance sites, and mastering the Heartbeat is a crucial step in that journey.
What is the WordPress Heartbeat API?
Introduced in WordPress 3.6, the Heartbeat API provides a way for the browser to communicate with the server in real-time. It uses a polling mechanism where the browser sends AJAX requests to the server at regular intervals (usually every 15 to 60 seconds).
The Heartbeat API is responsible for several key features:
- Autosaving Posts: Ensuring you don't lose your work if your browser crashes or your connection drops.
- Post Locking: Preventing two users from editing the same post simultaneously (the "Another user is currently editing this post" message).
- Real-time Notifications: Showing updates from plugins, such as e-commerce sales or security alerts, directly in the admin bar.
- Session Management: Checking if your login session has expired so you aren't suddenly logged out while writing.
Why Heartbeat Can Overload Your Server
The issue arises because every "pulse" is a call to admin-ajax.php. Each time this script runs, it bootstraps the WordPress core, loads your active plugins, and queries the database.
If you have multiple tabs open in your browser, or if you have multiple editors working on the site at once, those 15-second pulses multiply quickly. On shared hosting or even lower-tier VPS environments, this constant stream of requests can spike CPU usage to 100%, leading to 504 Gateway Timeout errors or a complete site slowdown.
How to Identify Heartbeat Issues
Before you start disabling features, you should confirm that Heartbeat is indeed the cause of your load.
Using Browser DevTools
- Open your WordPress dashboard.
- Right-click and select Inspect to open Developer Tools.
- Navigate to the Network tab.
- Filter by
XHR. - Wait for a minute. You will likely see repeated calls to
admin-ajax.phpwith the actionheartbeat.
Checking Server Logs
If you have access to your server's access logs, look for frequent POST requests to /wp-admin/admin-ajax.php. If these requests dominate your log files, it's time to optimize.
Method 1: Controlling Heartbeat with Code
For developers or those who prefer to keep their plugin count low, using a filter is the most efficient way to manage the API. You can add these snippets to your theme's functions.php file or a site-specific functionality plugin.
Slowing Down the Pulse
Instead of turning it off entirely, you can increase the interval between pulses. This reduces the frequency of requests while keeping features like autosave active.
add_filter( 'heartbeat_settings', 'xerowp_slow_heartbeat' );
function xerowp_slow_heartbeat( $settings ) {
$settings['interval'] = 60; // Set interval to 60 seconds
return $settings;
}
Disabling Heartbeat Everywhere
If you are the only person working on the site and you save your posts manually, you might choose to disable it entirely. Note that this will stop autosaves and post locking.
add_action( 'init', 'xerowp_stop_heartbeat', 1 );
function xerowp_stop_heartbeat() {
wp_deregister_script( 'heartbeat' );
}
Disabling Heartbeat on Specific Areas
Often, the Heartbeat API is most problematic on the frontend of the site (where it provides little value) or the general dashboard. You can selectively disable it while keeping it active in the Post Editor.
add_action( 'init', 'xerowp_conditional_heartbeat', 1 );
function xerowp_conditional_heartbeat() {
global $pagenow;
// Keep it on for post editing screens, disable elsewhere
if ( $pagenow != 'post.php' && $pagenow != 'post-new.php' ) {
wp_deregister_script( 'heartbeat' );
}
}
Method 2: Controlling Heartbeat with Plugins
If you aren't comfortable editing code, there are excellent plugins that provide a graphical interface for these settings.
1. Heartbeat Control (by WP Rocket)
This is the gold standard for managing this specific issue. It is lightweight and dedicated solely to this task.
- How to use: Install and activate, then go to Settings > Heartbeat Control.
- Configuration: You can set the behavior (Allow, Disable, or Modify) for the WordPress Dashboard, Frontend, and Post Editor separately. We recommend setting the Post Editor to "Modify" (60 seconds) and disabling it on the Frontend and Dashboard.
2. WP Rocket / Perfmatters
If you are already using a performance suite like WP Rocket or Perfmatters, you don't need an extra plugin. Both have built-in Heartbeat management tabs.
- In WP Rocket, navigate to the Heartbeat tab and check the "Control Heartbeat" box.
- In Perfmatters, go to the General tab and find the Heartbeat section.
Real-World Impact: A Case Study
At XeroWP, we recently assisted a client running a high-traffic WooCommerce store. Their server was hitting 90% CPU usage even during low-traffic periods. After auditing their site, we found that because they had multiple staff members keeping the orders page open in their browsers, the Heartbeat API was generating over 5,000 requests per hour.
By implementing a simple code snippet to increase the heartbeat interval to 60 seconds and disabling it on the frontend, we reduced the admin-ajax.php calls by 75%. The CPU usage dropped to a steady 20%, and the admin dashboard became significantly more responsive for the staff.
Best Practices and Recommendations
When managing the Heartbeat API, keep these best practices in mind:
- Don't Disable Completely in the Editor: Unless you are very disciplined about clicking "Save Draft," keeping the Heartbeat active in the post editor is a safety net you'll eventually be glad you have.
- Disable on the Frontend: Most sites do not need the Heartbeat API running for regular visitors. Disabling it here is an easy win for performance.
- Monitor After Changes: After tweaking the settings, keep an eye on your site's functionality. If you use plugins that rely on real-time data (like some auction plugins or live chat), they may require the Heartbeat to function correctly.
- Use Managed Hosting: A robust hosting environment like XeroWP is designed to handle AJAX requests efficiently, but even the best hardware performs better when the software is optimized.
Conclusion
The WordPress Heartbeat API is a powerful tool for collaboration and data integrity, but it shouldn't come at the cost of your server's health. By slowing down the pulse or disabling it where it isn't needed, you can significantly reduce server load and ensure a smoother experience for both your team and your visitors.
Ready to take your site's performance to the next level? Explore XeroWP's managed hosting plans designed for speed, security, and effortless scaling. Let us handle the server optimization so you can focus on growing your business.
