What Is WordPress Heartbeat API and How to Control It

As WordPress continues to develop and grow, many functionalities are now available to help boost the performance of websites. One of these new features is WordPress Heartbeat API, which was released in 2013. It lets browsers automatically connect with web servers via Ajax calls. It also helps sync all the data flowing between the browser and the server. 

However, there are a few drawbacks to WordPress Heartbeat API. It may not be ideal for websites using shared hosting primarily because it can overwhelm the servers’ CPU. To learn more about what this new feature is and how it works, let us discuss it further in this article.

What Is WordPress Heartbeat API?

The Heartbeat API gives websites a protocol for communication between the server and browser using AJAX calls. It sends continuous pulses or callbacks when receiving data. This helps websites sync all the information between WordPress dashboard and the server. 

One great benefit of the WordPress API is it provides an autosave functionality when you edit or create posts. Another is when a user edits a post, it locks the post from other users, so they cannot edit the same post. If you are using a plugin for ecommerce, the API will also show sales that are made on your website.     

Why Should You Limit WordPress Heartbeat API?

Despite the feature’s benefits, the Heartbeat API can be damaging in some situations. When it sends post or AJAX requests, it uses the /wp-admin/admin-ajax.php file. 

This type of request that uses the file is equivalent to CPU time on web servers. As a result, it creates a huge number of requests that are sent to the server, resulting in the exhaustion of the CPU.    

As mentioned earlier, this can be an issue if you are on a shared hosting plan. You might reach your limit, which forces your web hosting provider to suspend your account.

What to Consider Before You Disable Heartbeat API

Due to the major concern WordPress Heartbeat API may bring, you might consider stopping the feature completely. But before you do that, you need to think of it. 

Some things to be aware of are changes you make on a post will be lost if you do not press the Save Draft button. You will not have access to the WordPress Revisions feature as well. 

If you have plugins that restrict the Heartbeat API, you will not be able to take advantage of their functionalities and real-time updates. What you can do is manage Heartbeat API instead.  

How to Limit Heartbeat API Using a Plugin

Modifying WordPress Heartbeat API allows you to control the callbacks sent to your server. You can do this by installing the Heartbeat Control plugin. 

Once activated, go to Settings from your Dashboard menu and select Heartbeat Control

WordPress Plugins Dashboard

From there, you can see the General Settings section, and there are certain rules for API:

  • Frequency – This is the number of allowed callbacks for every location. Its range is 15-300 seconds. 
  • Locations – This identifies where you want Heartbeat API to control from. You have three options: Post Editor, Frontend, and WordPress Dashboard.
  • Heartbeat Behavior – This lets you modify, disable, and enable Heartbeat API.

You might want to limit the frequency to 200 seconds in the Post Editor. This is a practical option for websites with multiple authors. Select Modify Heartbeat to do this. 

Hearbeat Control

Do the same for the other locations if you want to change the frequency. Click Save Changes.

How to Stop WordPress Heartbeat API

If you opt for stopping Heartbeat API, you can use the plugin as well. Just select Disable Heartbeat for the locations you want it to stop.

You can also stop the feature without using a plugin. Go to the Appearance section of your Dashboard menu. Select Theme Editor and click Theme Functions (functions.php) at the right side of the page. Add the following code after the opening tag <?php:

add_action( ‘init’, ‘stop_heartbeat’, 1 );

function stop_heartbeat() {

wp_deregister_script(‘heartbeat’);

}

Theme Editor

Click Update File at the bottom to save the changes. Just remember that stopping Heartbeat API might be ideal if there are no plugins in your website that use this feature or you are the only user of your website.

Conclusion

WordPress Heartbeat API is an important feature for your website that needs to be controlled if you do not want to overwhelm your server’s CPU. This is especially true for websites that use shared hosting. You only need to use the Heartbeat Control plugin, so you can manage it effectively. Install the plugin now to create and edit posts hassle-free!

About Us
Innzone Hosting offers superior, reliable and affordable Web Hosting to individuals and businesses worldwide.

© Innzone Hosting. All rights reserved.