How to Reduce CPU Usage by Limiting WordPress Heartbeat API

How to Reduce CPU Usage by Limiting WordPress Heartbeat API

It’s always recommended to keep your website optimized because the CPU utilization is limited to most of the web hosting users. Most of the people have the shared server and every web hosting sends a notification for the over CPU utilization.

It’s really important to keep that as low as possible. WordPress introduced Heartbeat API in WordPress 3.6 which manages many things.

If the number of pulse increases, the number of CPU attempts assigned to your server also increases and eventually, it may end up in the downtime.

You wouldn’t want to let it happen. Most of the time if you get a message, the number of ajax requests are being made to wp-admin/admin-ajax.php by your website, it means you should control the WordPress Heartbeat API.

The Things WordPress Heartbeat API Manages

You may be wondering as if what’re the things this API controls and why everyone suggests to limit it.

  • It monitors the activities of all the authors on a multi-author website
  • It sends a pulse when you create/update a post
  • It sends a pulse when the blog posts autosave
  • Real-time sales data on an e-commerce website
  • Show notifications on the WordPress Dashboard

You may have experienced that when any other author is editing a blog post, you can see its status. It’s managed by this API.

Let’s say you have 5 authors and publish in a different category. The number of pulse/POST requests increases a lot during such situation.

And it directly impacts the CPU usage.

Just a few months ago, I was notified by my web hosting that the web hosting plan couldn’t handle my website and I had to upgrade to the cloud hosting.

Well, you know that it’s not easy to migrate from paying $15 per month to $50 per month. The web hosting customer support told me that the CPU daily attempts have been exceeded and it’s not possible to manage more.

That was because of the total number of the pulse sent by the WordPress Heartbeat API. I Googled and found the solution.

You should know that you can control the behavior of this API. You can even stop it if you’re the only author and don’t require to see the activity of other authors.

How You Can Monitor the Heartbeat API

There is no direct method which can let you know the exact number of the pulse sends by Heartbeat API. But you can see the old stats of your website from the cPanel.

This can be done using the built-in tool your web hosting company provides. If there is any, just ask them and check for the top 25 most visited pages.

If you see /wp-admin/admin-ajax.php on the top of the list, that’s it. The WordPress Heartbeat API has drained the CPU.

It’s preventing other actions to get performed and your website goes down. There are two different solutions to fix this.

Either you limit it or completely disable it. It can be done using a plugin or without any. As you know, most of the WordPress users are non-technical so they need to know the perfect plugin.

Manage WordPress Heartbeat API With a Plugin

Jeff Matson developed a plugin which can help you manage the frequency of the WordPress Heartbeat API with a few clicks.

Install and activate Heartbeat Control plugin. I hope you know how to install a WordPress plugin. Once you do that, go to Settings>>Heartbeat Control.

You will see three different options to override the default API settings.

There are many options to select the location from the drop-down menu. You can choose any depending on your requirements. If you’re the sole author, you can just disable it from everywhere.

By default, the frequency is set to 15 seconds for posts edit so you have to set any value greater than 15. The more you choose the later will be the POST request made by the Heartbeat API which will buy the CPU some time to execute other requests.

As I have mentioned before, most of the experts suggest to completely disable it. It doesn’t make any sense to spend hundreds of Dollars just because of this API.

Managing a shared web hosting can be really tricky and most of the users get charged too much. Even a website with 500 blog posts is forced to migrate to a VPS hosting or a Cloud hosting just to get more CPU daily attempts.

Limit WordPress Heartbeat API Using the Code

As you know, the functions.php file is one of the most important files present in the WordPress theme you use. You can add a simple code to this file and manage to set a limit for the Heartbeat API.

It’s just as same as you did above using a plugin. But many people avoid using plugins just to have such small issues solved. You can’t just install a plugin every time you have to do something new.

So it’s better to copy and paste this code. I assume you know how to edit the functions.php file.

If not, let me walk you through.

  • Open the cPanel and search for the file manager
  • Look for the wp-content folder
  • Then open themes
  • Select your theme name folder and look for functions.php

Open this to edit and paste the code shown below.

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

Save the file and you’re done.

A few people may get confused after opening the file manager. If you run multiple websites on the same web hosting, you should know where your website’s data is located.

I am sure, you have read about public_html. That’s the folder where you will find your website.

If you have access to your website’s dashboard, clear the cache from the caching plugin you use and try checking your website.

If everything seems fine, congrats, you have successfully managed to limit the WordPress Heartbeat API.

I hope you have understood why it’s important to keep your website optimized. Most of the people complain about the poor page loading time and the excessive use of CPU.

It’s really important to have an eye on the Heartbeat API. If you ever encounter such problem, try limiting or disabling it.

Enjoy using WordPress and have a smooth server uptime.

Check out the top 3 WordPress hosting services:

A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How to Edit the CSS for your WordPress Site Using the cPanel Hosting Control Panel

As you know, the design of a WordPress website is controlled by
4 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to deactivate all your WordPress plugins at once from cPanel

While handling a WordPress website, you may encounter with many common WordP
4 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Start an Online Store on the WordPress Platform

It’s an era of e-commerce and people always look for a better source to star
5 min read
Angela Olaru
Angela Olaru
Senior Writer & Hosting Expert

How to use Amazon RDS with your WordPress Installation

The default instance which is set up while creating an EC2 server with complete
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top