How to Limit or Stop WordPress Heartbeat API to Reduce CPU Usage

Limit or Stop WordPress Heartbeat API

Have you ever thought what’s responsible for showing you the activity of any other author to you? How can you see that someone is editing a post?

This is controlled by the Heartbeat API which was introduced in WordPress 3.6. There are many other functionalities provided by this API.

It’s very useful when you have a multi-author website but it can also create some problem. This API keeps checking the different pages of WordPress on a different time interval.

One call means one POST request which increases the CPU usage.

That’s the reason it’s recommended to limit or stop WordPress heartbeat API.

Stop the Heartbeat API Manually

If you’re the only person who is handling your website then you don’t need this API. You should disable it completely from your website.

It can be done by adding a code snippet in the functions.php file of your WordPress theme.

You can access this file either from the dashboard or the cPanel of your web hosting account. Just go to Appearance>>Edtior>>functions.php file.

From the cPanel, go to file manager>>public_html>>wp-content>>themes>>theme name>>functions.php file.

Though it’s always recommended to create a child theme for adding any extra code still if you are sure that you can handle it, go ahead.

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

Add this code at the last in the file and save it.

From now onwards, your website isn’t going to make those heartbeat execution requests. The CPU of your web hosting server will be free from these regular POST requests.

This is the method recommended for the people who know a little bit about coding and how to add custom code in WordPress properly.

Limit or Stop WordPress Heartbeat API Using a Plugin

If you’re not comfortable with the above method, you can install and activate the Heartbeat Control plugin.

You can choose the locations of the Heartbeat API at which, you want to disable it. Do you want to keep it active on the dashboard or the post edits?

The choice is yours.

I would recommend using the default location.

By default, the heartbeat API makes a POST request every one minute on the dashboard and 15 seconds on the post edit pages.

 You can limit it according to you.

control WordPress heartbeat API

But if you want to stop it then just disable it for everywhere. No default use, just block it for both the dashboard and the post edit pages.

Save the settings and you’re done. There would be no more POST requests executed and your CPU will face no more problem.

It somehow reduces the CPU usages to a greater extent. When the size of your website keeps increasing, you can face the problem due to thousands of execution requests.

To avoid them, you should limit or stop WordPress heartbeat API. If you have any doubt, feel free to ask.

You can also connect with us on Twitter, LinkedIn, and Facebook.

by Ravi Chahar

A WordPress Professional and a LinkedIn influencer. A coder by passion and a blogger by choice. WordPress theme development is what he can rock with. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, theme development, design issues and what not.

4 comments

  1. Hello Ravi,

    Thanks for this great tutorial. I just want to know that If I stop the heartbeat execution, will it impact my site performance? I mean does it create any conflict with plugins and themes? Please advice.

    1. Hey Viswajeet,

      It doesn’t have any anything to do with the plugins and the themes. It works on the WordPress core. And it will help you reduce the CPU use. For shared hosting, people face this problem and everyone recommends to upgrade the web hosting plan. But this can help.
      ~Ravi

  2. Hi Ravi. You have certainly learned a lot about the inner workings of WordPress.

    I’m going to add your code snippet to my theme on one of my websites and see how it works.

    What impact if any does the heartbeat have on multi-site installations?

    1. Hey Wayne,

      For a multisite installation, it’s not a good idea because you wouldn’t come to know who is editing which post. It may impact your monitoring system.
      Thanks for stopping by.
      ~Ravi

Leave a Reply

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