How To Limit Heartbeat API in WordPress

Automation is the market demand. WordPress has been considering sophisticated automation between web browsers and servers for a long time.

With WordPress 3.6, the Heartbeat API was introduced to improve communication between web browsers and servers.

The Heartbeat API provided a much-needed opportunity for plugin developers to connect to a web server using the API quickly.

It made their life much easier as they no longer needed to write thousands of lines of code to connect to web servers. Instead, they have to use the heartbeat API to connect.

Though the heartbeat API has many valuable features, it may also slow down your website. This is due to the excessive API calls that the heartbeat API makes to a web server.

Slow-loading websites result in a poor user experience and a high bounce rate. Limiting the heartbeat API is necessary if you want to improve your website’s performance.

So, in this article, we will talk about How to limit Heartbeat API in WordPress.

What Is Heartbeat API

As the name suggests, Heartbeat API is a communication protocol between web browsers and servers. It uses AJAX calls to communicate.

If many plugins utilize the heartbeat API, a large number of AJAX calls will be made to the web server. This, in turn, slows down the website’s loading speed.

You might be wondering, if this heartbeat API has so many issues, then why do we need it?

The Heartbeat API offers several exciting features that many end users may find very useful.

Below are a few features that the Heartbeat API offers.

  • Enables post-revision features in the WordPress dashboard
  • Autosave posts
  • Lock post-editing for a multi-authored blog
  • Show all notifications in the WordPress dashboard
  • Shows real-time sales data for WooCommerce stores

How Heartbeat API works

The Heartbeat API utilizes theΒ admin-ajax.phpΒ file, located under “/wp-admin/admin-ajax.php”,Β to send AJAX calls to communicate with the web server.

At times, when many plugins use the heartbeat API, it stops responding, and you will be presented with a CPU overutilization error.

The heartbeat API triggers pulses every 15 seconds to ensure a connection between the web server and the web browser.

Each pulse executes one PHP script and thus makes one CPU call to the web server. WordPress throws a connection error if the pulse takes more than 30 seconds to get a response.

How To Monitor Heartbeat API

There is no option in the WordPress dashboard to check the usage of the Heartbeat API. You can ask your web host to send a report of CPU utilization statistics. You can also use the statistics data from your C-Panel dashboard.

The image below shows a snapshot of a C Panel.

Limit Heartbeat API In WordPress

The GTMetrixΒ waterfall chart is the simplest way to check which plugins or files might be using the heartbeat API.

Sometimes, you may not see any plugin name, and you may only see some code. Searching with those codes on Google may help you determine which plugin uses the API and fix it accordingly.

How To Disable Heartbeat API in WordPress

You may have noticed thatΒ ta_link_fixerΒ uses the heartbeat API in the above waterfall chart. A quick Google search revealed that this issue is caused by an option in the plugin “Thirsty Affiliates“.

The heartbeat API issue disappeared when I unchecked the option and ran the GTMetrix analysis. I also noticed that my website loads faster once the heartbeat API is stopped. You can see the difference in the fully loaded time.

The image below shows the improvement in speed after I stopped the heartbeat API.

How To Disable Heartbeat API in WordPress

Implications of using Heartbeat API

Heartbeat API not only slows down your website but can also have more severe implications if you use shared hosting.

Typically, all shared hosting plans allow a finite CPU utilization, although they say they offer unlimited bandwidth.

Once you hover near your account’s maximum CPU utilization, the web host will send a warning email.

If you don’t take measures to reduce CPU utilization, your hosting account may be temporarily suspended.

A repeated temporary suspension will result in a permanent suspension, with no refunds. Hosting companies follow this practice to ensure that every account receives equal resources in a shared hosting environment.

How to Disable WordPress Heartbeat API

The best way to limit the Heartbeat API in WordPress is to delete all plugins that utilize the Heartbeat API.

Sometimes it is not possible, as you will lose many functionalities. In this case, you may choose to limit the frequency of API calls. You can restrict API calls using the following methods.

  • Using a plugin
  • Adding a few lines of code in the function.php file

Disable WordPress Heartbeat API Using A Plugin

Using a plugin to limit the heartbeat API in WordPress is advisable. If you are not tech-savvy, using a plugin can save you from unnecessary issues.

Perfmatters is the best for enabling or limiting Heartbeat API among all those plugins.

Below are the steps to follow.

1. Go To Perfmatters Plugin Setting

You must log in to the WordPress dashboard-> Settings -> Perfmatter to access the Perfmatter settings.

How To Disable Heartbeat API in WordPress

2. Go To the General Tab

Under settings, go to the “General” tab.

How To Disable Heartbeat API in WordPress

3. Access The Heartbeat Tab

Scroll down to the Heartbeat API option in the general tab.

How To Disable Heartbeat API in WordPress

Under the ” Disable Heartbeat” option, choose from the following options.

How To Disable Heartbeat API in WordPress

If you choose the option “Disable Everywhere,” you don’t need to set the frequency. If not, you can select the frequency here.

limit heartbeat API

Ideally, you can keep the Only Allow When Editing Posts/ Pages” optionΒ checked unless you feel your dashboard is slow.

That will ensure you can still access features like Auto-Save, Post revisions, Live statistics, etc. If you don’t need those features, you can select ” Disable Everywhere.” This will disable the heartbeat API on both the backend and the frontend.

If you want to use WP Rocket to disable the heartbeat API, refer to the following video.

YouTube video thumbnail

Disable WordPress Heartbeat API Without A Plugin

If you don’t want to install a plugin to control the heartbeat API, you can use the following code to stop the API from making any calls.

If you use a child theme, you can add these lines of code to the function.php file available in the child theme folder.

It is always advisable to back up the file before making any changes so that you can retrieve it in case something goes wrong.

add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

Conclusion: How to Limit WordPress Heartbeat API

If you are a solo blogger and no other authors are accessing your WordPress dashboard, then it is high time to disable the heartbeat API.

That will save your bandwidth, and the website will be much faster. You can even disable the heartbeat API in the post editor.

I know you will miss the auto-save and post-revision features if you do so. However, you can always write your article in Google Docs and paste it into your WordPress post editor when it’s done.

You may know that every second’s delay costs you about 40% of the visitors. Do you want to lose those visitors just because of Heartbeat API?

I believe now you knowΒ how to disable the heartbeat API in WordPress. Go ahead and disable the heartbeat API to enjoy a faster-loading website.

That’s all I have in this article. Do you see any other issues that are affecting your website’s speed? If so, please write in the comment section, and I will try to offer a solution.

FAQ | Limit Heartbeat API

What Is Heartbeat API In WordPress?

The Heartbeat API is a communication protocol for WordPress that facilitates communication between a web browser and a web server.

With Heartbeat API, WordPress developers do not need to write hundreds of lines of code to create a communication protocol between a web server and a web browser. Instead, they can use the Heartbeat API

The Heartbeat API utilizes AJAX calls to facilitate communication.

How To Disable Heartbeat API?

You can disable the Heartbeat API by adding the following piece of code in the function.php file located in the child theme directory.

add_action( ‘init’, ‘stop_heartbeat’, 1 ); function stop_heartbeat() { wp_deregister_script(‘heartbeat’); }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top