How to Limit Heartbeat API in WordPress

How To Manage HeartBeat API

Did you notice that your website is loading very slow although you have a clean coded theme and few plugins, Did everything possible but still no luck? Scratching your head on what could be the reason?

Automation is market demand nowadays. Off late WordPress started thinking about sophisticated automation between web browsers and web servers. With WordPress 3.6, HeartBeat API was introduced to communicate between a web browser and web server in a better way.

Heartbeat API brought a much-needed opportunity for plugin developers to quickly connect to a web server using the API. It made their life much easier as they no longer need to write thousands of line of codes to connect to web servers. Instead, they have to use heartbeat API to connect.

Though heartbeat API brought many useful 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 lead to poor user experience and a high bounce rate. Limiting the heartbeat API is a must if you want to speed up your website. 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 the web browser and web server. It uses AJAX calls to communicate. If so many plugins use heartbeat API, a huge number of AJAX calls will be made to the webserver. This in turns slows down the website loading speed.

You might be wondering, when this heartbeat API has so many issues, then why do we really need it? Well, this API comes with some exciting features which many end users may find it very helpful. Below are a couple of features that heartbeat API offers.

  • Enables post revision features in WordPress dashboard.
  • Autosaves drafted posts in every 15 seconds.
  • Lock post-editing for a multi-authored blog.
  • Show all notifications in WordPress dashboard
  • Shows real-time sales data for Woo Commerce stores

How Heartbeat API works

Heartbeat API uses admin-ajax.php file located under “/wp-admin/admin-ajax.php“ to send AJAX calls for communicating with the webserver. At times when many plugins use the heartbeat API, it stops responding and you will be presented with CPU overutilization error.

The heartbeat API trigger pulses every 15 seconds to make sure there is a connection between the web server and web browser. Each pulse executes one PHP script and thus make one CPU calls to the webserver. If the pulse takes more than 30 seconds to get a response, WordPress throws a connection error.


How to monitor Heartbeat API

There is no option in the WordPress dashboard to check the uses of 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.

If you use SiteGround or any other managed WordPress hosting, you may be having their statistic tools which you can refer to check Heartbeat API uses. Below option shows how you can access this data in your SiteGround dashboard.

SiteGround Dashboard -> Select Website -> Site Tools -> Statistics -> Traffic -> Behavior

If you refer to the above image, you can notice that the Admin-Ajax.php file is at the top of the most visited page. What that means is that the blog is using heartbeat API. You can also check the GTMetrix waterfall chart to diagnose if your blog is using heartbeat API or not. The details of the same are explained in the next paragraph.


How to diagnose plugins using Heatbeat API

GTMetrix waterfall chart is the simplest way to check which plugins or file might be using heartbeat API. Sometimes you may not see any plugin name and you may only see some codes. Searching with those codes may help you to figure out which plugin is using the API and fix accordingly.

Limit heartbeat API in WordPress

In the above waterfall chart, you may have noticed that ta_link_fixer is using the heartbeat API. A quick googling discovered that this is caused by an option the plugin ” Thirsty Affiliates“. When I unchecked the option and run the GTMetrix analysis, the heartbeat API issue disappears. I also noticed that once the heartbeat API is stopped, my website is loading much faster than before. You can notice the difference in fully loaded time.

limit heartbeat API in WordPress

Severe implications of using Heartbeat API

Heartbeat API not only slows down your website, but it can have more severe implication if you are using shared hosting. Typically all shared hosting allows a finite number of CPU utilization although they tell that they offer unlimited bandwidth. Once you are hovering near to maximum CPU utilization of your account, the web host will send a warning email.

70% Off

Buy SiteGround Hosting at $3.95 / Month

Buy SiteGround Managed hosting plan just at $ 3.95 / Month and save up to $287 for 36 month. . Don’t Miss it.

More Less
Doesn't expire

If you don’t take measure to reduce CPU utilization, they may even suspend your hosting account temporarily. A repeated temporary suspension will lead to a permanent suspension without any refunds. Hosting company follows this practice to make sure every account gets equal resources in a shared host environment.


Recommended Read : How to disable WordPress default cron jobs

How to Disable WordPress Heartbeat API

The best way to limit heartbeat API in WordPress is to delete all those plugins which are using Heartbeat API. Sometimes it is not possible as you will be losing a lot of functionalities. In this case, you may choose to limit the frequency of API calls. You can limit API call using the following methods.

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

Warning !

Always back up your website before doing any change. Stopping heartbeat API will stop Auto save, Post revisions, real time statistics and other plugin related feature which were using Heartbeat API

Disable WordPress Heartbeat API using plugin

It is advisable to use a plugin to limit the heartbeat API in WordPress. If you are not a tech-savvy, using a plugin can save you from unnecessary issues. Among all those plugins, Heartbeat Control is the best as it is developed by the same team who developed WP Rocket. Below is a quick overview of the plugin.

limit heartbeat api in wordpress

Once the plugin is installed you can head over to Settings -> Heartbeat Control to have the settings page of the plugin. You will be presented with heartbeat API controls in different scenarios as mentioned below.

  • WordPress Dashboard
  • Front end
  • Post-Editor

Ideally, you can keep the Heartbeat API running in the WordPress dashboard unless you feel that your dashboard is super slow. On the front end, the heartbeat API should be disabled all time as it affects the user experiences. In the case of Post Editor, it is preferable to disable the heartbeat API unless you want to have features like Auto-Save, Post revisions, Live statistics etc.

In the settings page, you can also modify the pulse increment time instead of disabling it. For each scenario, it has a modify option where you can modify the pulse timings. By default, it is 15 seconds and you can change it to anything you want. The modify pulse timing is really useful as it helps you speed up your blog but at the same time, you can enjoy the heartbeat features.

Control WordPress Heartbeat API without a plugin

If you don’t like to install a plugin for controlling the heartbeat API, you can use following codes to stop the API making any calls. If you are using a child theme, you can add these line of codes in the funtion.php file available in the child theme folder. It is always advisable to take a backup of the file before making any changes so that if in case something goes wrong, you can retrieve that.

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 heartbeat API. That will save your bandwidth and website will be much faster. You can even disable heartbeat API in the post editor. I know by doing so you will miss the auto-save and post revision features. But you can always write your article in Google Docs and paste the same in your WordPress post when it’s done.

You may know that every second’s delay cost you about 40% of the visitor. Do you want to lose those visitors just because of Heartbeat API? I believe now you know How to disable heartbeat API in WordPress. So go ahead and disable heartbeat API and enjoy a faster loading website.

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

Before you leave this page, you may like to have a glimpse of recommended articles which may help you to do blogging in a better way.



5 thoughts on “How to Limit Heartbeat API in WordPress”

  1. Thank you for sharing this tip with me. I’m having a problem with a post at the backend. WordPress stops responding whenever I open the post in draft, but in preview, it works well. So when I saw this post I was happy and hope it would really help me. Thanks again.

    1. It could be one of the possible reason but other factors may also contribute. Have a try and if that does not solve the problem we may need to look for the root cause.

Leave a Comment

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

About Me

About Me

Hey, Myself Rajib, I share Blogging Tips & tutorials on WordPress in this blog. I also write on Advanced Technologies In RiansClub. If you want to know more about me, Please follow me on Facebook or subscribe to my YouTube Channel

Tools We Recommend

Get Exclusive Blogging Tips

Join our newsletter and get exclusive proven blogging tips and updates every week directly in your Inbox.

Select Your Topic

Recent Posts

Disclaimer

This Web page may contain certain affiliate links of products and/or services. We may earn a small commission ( Without any extra cost to you)  if you buy any product or services by clicking on those link. For more information please read our affiliate disclosure.

Give Your Blog A Rocket Like Speed Boost
Scroll to Top