What Is WordPress Heartbeat API and How to Manage it

?

The WordPress Heartbeat API is a feature introduced in WordPress 3.6 that allows a browser to communicate with the server. It uses AJAX calls to send and receive data from the server. This allows WordPress to perform tasks such as autosave, post locking, and log-in expiration warnings.

The Heartbeat API can be managed by using the Heartbeat Control plugin. This plugin allows you to control the frequency of the Heartbeat API calls, as well as disable it completely. You can also set the frequency of the calls for specific pages or post types. This can help reduce server load and improve performance.
[ad_1]

In 2013, WordPress introduced Heartbeat API – a feature that allows your browser to communicate automatically with the server. However, there are a couple of drawbacks to this feature.

If you use a Shared Hosting plan, you need to take a closer look at the CPU usage of your server. That’s because some hosting companies might suspend your account when you go over the limit.

Here, we’ll talk about why WordPress Heartbeat API is the usual suspect that causes the issue.

What Is the WordPress Heartbeat API?

WordPress Heartbeat API provides a communication protocol, using AJAX calls, between the browser and the server.

As the name implies, the API will send continuous pulses and trigger events (or callbacks) upon receiving data. This function helps you to sync all the data between the server and the WordPress dashboard.

The idea behind heartbeat API is quite compelling. For example, when you create/edit a post from the editor, it provides a function to autosave the post periodically.

In a collaborative WordPress site, it has a post-locking function to prevent you from editing a post that’s being worked on by another user. If you use an eCommerce plugin, this API will also help to display sales that happen on your site.

Why Limit WordPress Heartbeat API?

While it’s beneficial to have an autosave function and real-time data notification features, it can be harmful in a specific situation.

Heartbeat API sends AJAX requests (POST requests) using the /wp-admin/admin-ajax.php file. Each request that executes a PHP file is equal to CPU time on the server.

This can cause a large number of requests sent to the hosting server, which results in high CPU utilization.

As we noted earlier, this can be a problem for a webmaster with a shared hosting plan. As you reach your quota limit, high CPU usage can eventually lead to account suspension. So be sure to check how to fix spikes in your admin ajax file.

Things to Consider Before Stopping Heartbeat API

If you’re thinking of stopping the Heartbeat API completely, you need to think about it twice. It’s not because you can’t do that, it’s just not practical.

Without the WordPress Heartbeat API, all the changes you made in the post will be lost should you ever forget to click the Save Draft button. And you will no longer have access to the Revisions feature in WordPress.

If you install WordPress plugins that use Heartbeat API, you also can’t display the real-time notifications and information features on your site.

But, if you’re working alone, and all of these functions do not matter much to you, you can then proceed to stop the WordPress Heartbeat API.

Otherwise, you might consider controlling the API instead.

How to Limit the WordPress Heartbeat API With a Plugin?

You can control how often the Heartbeat API sends callbacks to your server using the Heartbeat Control plugin.

Once you have installed and activated the plugin, go to Settings -> Heartbeat Control Settings. Here, you can set a certain rule for the API.

  • Heartbeat Behavior – allows you to Enable Heartbeat, Disable Heartbeat, or Modify Heartbeat
  • Locations – determines which area you want to control the API from; it provides you with three options: WordPress Dashboard, Frontend, and Post Editor
  • Frequency – the number of callbacks you allow for each determined location. The value ranges from 15 to 300 seconds
The WordPress Heartbeat Rule settings in the Heartbeat Control plugin

In the example, we limit the frequency of the Heartbeat API function in Post Editor to 200 seconds. This is a more practical approach if you have multiple authors working on the same WordPress site.

You can also set the value differently in each location you wish to control. Just click Add Another Value button, and adjust it accordingly.

This plugin also allows you to completely disable the WordPress Heartbeat API altogether. You can do so by choosing Disable Heartbeat for the Heartbeat Behavior.

How to Completely Stop Heartbeat API Without a Plugin?

You can also stop the Heartbeat API without a plugin by adding this code snippet to your active theme functions.php file.

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

Please remember, you should do this if you’re the only person working with the website and you don’t need to install additional plugins that use this API.

Edit the function.php file to disable WordPress heartbeat

From your WordPress Dashboard, go to Appearance -> Theme Editor. Make sure you’re editing the active theme of your site. Click Theme Functions (functions.php) from the right-hand navigation menu. Paste the code snippet above right after the opening <?php tag and click Update.

That’s it, and now you’ve successfully disabled the WordPress Heartbeat API on your site.

Conclusion

You’ve learned about the WordPress Heartbeat API and the functionality it gives to your site. Although it’s undoubtedly beneficial, in a shared hosting environment, it can cause quite a problem should you not handle it well.

To reduce the CPU usage on your server, you can either control the API or completely disable it. Also, you can do it using a plugin or manually adding code to the functions.php file.

[ad_2]

What Is WordPress Heartbeat API and How to Manage it

WordPress Heartbeat API is a feature introduced in WordPress 3.6 that allows your browser to communicate with the server. It is used to keep track of user activity and manage tasks such as autosave, revision tracking, and log-in expiration. It also helps to keep your WordPress site secure by preventing malicious activities.

The WordPress Heartbeat API works by sending a request to the server every 15-60 seconds. This request is used to check for any changes in the user’s activity or any other tasks that need to be done. If there are any changes, the server will respond with the necessary information.

The WordPress Heartbeat API can be managed by using the Heartbeat Control plugin. This plugin allows you to control the frequency of the requests sent to the server. You can also disable the API completely if you don’t need it. This is useful if you want to reduce the load on your server or if you don’t want the API to interfere with other plugins.

The WordPress Heartbeat API is a useful feature that helps to keep your WordPress site secure and up-to-date. It is important to manage it properly to ensure that it is not causing any performance issues or security risks. The Heartbeat Control plugin is a great way to manage the API and ensure that it is working properly.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00