WordPress Heartbeat API: The Hidden Requests That Can Slow Down Your Website
When troubleshooting a slow WordPress website, most developers start by checking plugins, themes, caching, and database queries. But have you ever considered that WordPress itself might be generating repeated background requests?
That's exactly what I discovered while investigating a client's website. In my previous article {:target="_blank"}, I shared how a client's WordPress website had numerous plugins installed and was experiencing performance problems. During my investigation, I contacted the hosting provider's support team and asked them to examine the server logs.
Their response surprised me. They reported a massive number of requests associated with something called the WordPress Heartbeat API. At the time, I wasn't familiar with Heartbeat or how it worked. So I started researching it. What I discovered was an important WordPress feature that many developers use indirectly without realizing it.
In this article, I'll explain what the WordPress Heartbeat API is, how it works, when it can affect performance, and how to investigate and control it safely.
1. What Is the WordPress Heartbeat API?
The WordPress Heartbeat API is a built-in feature introduced in WordPress 3.6. It allows communication between the user's browser and the WordPress server at regular intervals without requiring a full page reload. This communication uses AJAX requests.
Heartbeat supports several important WordPress features, including:
- Post locking: Prevents multiple users from editing the same post simultaneously.
- Autosave-related functionality: Helps the editor communicate with WordPress while content is being edited.
- Session monitoring: Helps WordPress detect authentication-related changes.
- Plugin functionality: Allows plugins to exchange information with the server periodically.
For example, imagine two authors working on the same WordPress website. When one author starts editing a post, WordPress can notify the second author that the post is already being edited. Heartbeat helps make that communication possible.
It's a useful feature, but it also creates server requests.
2. How Does WordPress Heartbeat Work?
Heartbeat uses JavaScript on the browser side and PHP on the server side. The process is relatively straightforward:
- A user opens a WordPress administration page.
- WordPress loads the Heartbeat JavaScript functionality where it is enabled.
- JavaScript periodically sends an AJAX request to the server.
- WordPress processes the request.
- The server returns a response.
- The process repeats while the relevant page remains active.
These requests commonly use the following endpoint:
/wp-admin/admin-ajax.php
For example:
POST /wp-admin/admin-ajax.php
The request typically includes an action parameter:
action=heartbeat
The important detail is that admin-ajax.php is not exclusive to Heartbeat. Many WordPress plugins and themes also use this endpoint for their own AJAX operations. Therefore, seeing requests to admin-ajax.php doesn't automatically mean Heartbeat is responsible. You need to inspect the request payload to identify the action.
How frequently does Heartbeat run? Heartbeat uses a configurable interval that varies depending on the WordPress context and activity. A commonly used default interval is around 15 seconds, although actual behavior can differ between screens and configurations.
Heartbeat can also slow its polling when browser activity changes. This means it isn't necessarily sending requests at a fixed rate under every condition.
3. Why Can Heartbeat Affect Website Performance?
A single Heartbeat request usually isn't a problem. The concern arises when many requests are generated or when processing them becomes expensive.
Consider a simplified example. Suppose Heartbeat sends one request every 15 seconds. That means approximately:
- 4 requests per minute
- 240 requests per hour
Now imagine 10 users have WordPress administration pages open simultaneously. Under those simplified assumptions, the site could receive:
- 40 requests per minute
- 2,400 requests per hour
These are illustrative calculations, not measurements from my client's website. Actual request counts depend on browser activity, WordPress configuration, and other factors. Each request may require PHP processing and could trigger additional plugin callbacks. On a server with limited resources, excessive or expensive requests can contribute to performance problems.
Multiple open browser tabs
An administrator might have several WordPress dashboard tabs open. If Heartbeat is active in multiple tabs, each may generate periodic requests.
Plugins using Heartbeat
Some plugins extend Heartbeat with their own functionality. Poorly optimized callbacks can increase the amount of processing performed during a Heartbeat request.
Limited hosting resources
On hosting environments with constrained CPU or PHP worker capacity, background requests can compete with other requests for resources. However, Heartbeat requests alone don't prove the cause of a performance issue. They are a signal worth investigating.
4. How to Identify Heartbeat Requests
You don't necessarily need a performance plugin to inspect Heartbeat activity. Your browser's developer tools are a useful starting point.
Step 1: Open WordPress Admin
Log in to your WordPress dashboard and open a page where Heartbeat is active, such as the post editor.
Step 2: Open Developer Tools
In Chrome or Firefox, press:
F12
Navigate to the Network tab.
Step 3: Filter AJAX Requests
Select the Fetch/XHR filter. Look for requests to:
admin-ajax.php
Leave the page open long enough to observe whether requests repeat.
Step 4: Inspect the Request
Click a request and inspect its payload. Look for:
action: heartbeat
If you see that action, you've identified a Heartbeat request. You can also inspect the request's timing and response. Remember that the total request duration isn't the same as PHP execution time, and a slow request doesn't necessarily mean Heartbeat itself is inefficient.
Step 5: Check Server Logs
Browser DevTools show requests from your own browser session. Server logs can help reveal request patterns across the website. You can ask your hosting provider to investigate:
- The number of requests to
admin-ajax.php. - How many of those requests are associated with Heartbeat.
- Whether requests correlate with CPU or memory spikes.
- Whether specific PHP processes or plugin callbacks are expensive.
- Whether the requests coincide with the reported performance problems.
This is exactly why contacting hosting support was valuable in my client's case. The logs gave me a technical lead that wasn't obvious from looking at the website.
5. How to Control WordPress Heartbeat Safely
Once you've confirmed that Heartbeat activity deserves investigation, you can consider adjusting its behavior. However, I wouldn't recommend disabling it globally as a first step. Heartbeat supports useful functionality, and changing it can affect the editing experience.
Option 1: Adjust the Heartbeat Interval
WordPress provides the heartbeat_settings filter, which lets developers modify Heartbeat settings. For example:
add_filter( 'heartbeat_settings', function( $settings ) {
$settings['interval'] = 60;
return $settings;
} );
This example sets the polling interval to 60 seconds. You can place the code in a small custom plugin or another appropriate location where your WordPress customizations are managed.
The interval is subject to WordPress's supported limits, and the effective polling behavior may vary depending on the page and activity.
Important: Increasing the interval reduces polling frequency, but it also means Heartbeat-dependent updates may take longer. Always test the affected functionality.
Option 2: Adjust Heartbeat Only on Selected Screens
Rather than changing the interval everywhere, you can apply a different setting on a particular administration screen. For example:
add_filter( 'heartbeat_settings', function( $settings ) {
if ( ! is_admin() ) {
return $settings;
}
$screen = get_current_screen();
if ( $screen && 'dashboard' === $screen->id ) {
$settings['interval'] = 60;
}
return $settings;
} );
This example targets the main WordPress dashboard screen. It doesn't globally disable Heartbeat or change the post editor's interval. Screen-specific changes can be preferable when you've identified a particular area that needs adjustment.
Option 3: Disable Heartbeat on a Specific Screen
WordPress also provides a way to dequeue scripts. For example:
add_action( 'admin_enqueue_scripts', function( $hook ) {
if ( 'index.php' === $hook ) {
wp_dequeue_script( 'heartbeat' );
}
}, 100 );
This example attempts to remove Heartbeat from the main dashboard page. It should only be used after confirming that no required functionality on that screen depends on Heartbeat.
I would avoid disabling Heartbeat throughout the administration area, especially in the post editor, without understanding the consequences. My preference is to investigate and make targeted adjustments rather than disabling core functionality blindly.
6. How to Verify Your Changes
After changing Heartbeat settings, return to the browser's Network tab. Check whether the frequency of Heartbeat requests has changed as expected.
Then test important WordPress functionality. For example:
- Open the post editor.
- Check whether editing and autosaving behave correctly.
- Test post locking with another user account, if available.
- Verify that any plugin functionality relying on Heartbeat still works.
- Review server resource usage and logs.
Ideally, compare measurements before and after the change under similar conditions. If you have access to server monitoring, look at PHP worker utilization, CPU activity, and request volume.
A reduction in Heartbeat requests doesn't automatically prove that the website became faster. The objective is to determine whether the change improved the original problem without introducing new issues.
7. What I Learned from This Experience
When the hosting provider first mentioned WordPress Heartbeat, I didn't know much about it. I had worked with WordPress for years, but this particular feature wasn't something I had previously needed to investigate in detail.
The experience reminded me of three important lessons.
- Server logs can reveal problems you don't see in the browser
Looking at the website's frontend doesn't always reveal what is happening on the server. Logs and resource metrics can provide valuable evidence.
- Not every performance issue requires another plugin
Plugins can be useful, but adding one without understanding the problem can make the setup more complicated. Sometimes WordPress already provides the hooks and tools needed to investigate or adjust a feature.
- Good developers don't need to know everything
What matters is the ability to investigate unfamiliar behavior, understand the underlying system, and evaluate possible solutions. In my case, a real client problem motivated me to learn about a WordPress feature I hadn't previously explored. And that knowledge became useful beyond the original project.
8. Heartbeat vs. WP-Cron: Are They the Same?
One final point worth mentioning is that Heartbeat and WP-Cron are different mechanisms.
Feature Heartbeat API WP-Cron Purpose Periodic browser-server communication Scheduled WordPress tasks Typical trigger Browser-side JavaScript WordPress's cron spawning mechanism Common endpoint admin-ajax.php wp-cron.php Example use Post locking Scheduled publishing Performance concern Excessive or expensive AJAX requests Excessive, delayed, or expensive scheduled tasks
Both are worth understanding when troubleshooting WordPress performance, but they should not be confused. In my next article, I'll explore WP-Cron in more detail, including how it works, why scheduled tasks sometimes fail or run late, and when using a real server cron job can be useful.
Final Thoughts
The WordPress Heartbeat API is not a bug or an unnecessary feature. It provides useful functionality that helps WordPress deliver a better editing and administration experience. However, like any server-side activity, it can contribute to performance problems under certain conditions.
The key is understanding how it works, measuring its impact, and making changes only when the evidence supports them. My experience with a client's website taught me that troubleshooting isn't always about finding a new tool. Sometimes it's about discovering a feature you didn't know existed.
Before disabling Heartbeat or installing another optimization plugin, investigate the requests and understand what's actually happening.
I'm a WordPress developer specializing in custom WordPress development, WooCommerce, PHP, and JavaScript. You can explore my work on GitHub. If you've encountered excessive Heartbeat requests on a WordPress website, I'd be interested to hear how you investigated them. Have you ever discovered an unexpected WordPress feature while troubleshooting a client project?
Comments
No comments yet. Start the discussion.