How to Limit the WordPress Heartbeat API?

Many WordPress users can improve the performance of their website on shared hosting plans by limiting the default settings of the Heartbeat API. The functionality of the Heartbeat API is related to the /wp-admin/admin-ajax.php file. 

This guide will explain the basic settings options.

The Heartbeat API uses AJAX calls to synchronize content, plugins, and other information when multiple users are active on a WordPress site. Turning off the Heartbeat API can improve WP performance by reducing the total number of PHP calls made to a server. 

Table of Contents:

  1. What is WordPress Heartbeat?
  2. What is WordPress Heartbeat used for?
  3. How to Configure WordPress Heartbeat?
  • How to Limit the Heartbeat API?
  • How to Stop Heartbeat Completely?
  • Other Heartbeat API Settings
  1. When might Heartbeat be harmful to your website?
  2. Conclusion
  3. FAQ

The Heartbeat API has been part of WordPress core since version 3.7. Multiple third-party plugins available for WordPress allow admins to limit or completely turn off the functionality. 

ScalaHosting recommends looking into the Heartbeat Control plugin by WP Rocket and the Perfmatters plugin as two of the best tools to control the Heartbeat API. 

What is WordPress Heartbeat?

The Heartbeat API represents a JQuery event that is scheduled in the WordPress core whenever a user is logged into the admin account. The API functionality has three main aspects:

  • JS heartbeat-send event: Developers can add variable data to the communication
  • Heartbeat_received filter: The AJAX code is processed by PHP, updating the CMS.
  • JS heartbeat-tick: The process confirmation is returned to the source plugin.

Developers can incorporate the Heartbeat API functionality into custom plugins to ensure that information is being updated across active website users in real-time. This allows multiple users to edit the same content simultaneously, with CMS updates communicated every 15-20 seconds.

What is WordPress Heartbeat used for?

The WordPress API can display which users are actively editing a page at the same time in the CMS. The functionality can relay content updates with timestamps that are logged by page analytics. Developers can customize queries to relay real-time update messages to users.

Still, the Heartbeat API is primarily utilized to auto-save content when it is in the process of being edited. It can also log WooCommerce shopping cart information in real-time for analytics purposes. On top of it all, developers can extend the functionality as per the requirements of their plugins.

How to Configure WordPress Heartbeat?

The main problem with the Heartbeat API is that it can needlessly increase PHP processing requirements on a shared server, and there is no default administration for the service in the WP core. 

In such cases, web developers can use third-party solutions or disable the API altogether.

WP Rocket and Perfmatters both produce proprietary performance optimization plugins for WordPress. 

The Heartbeat Control plugin from WP Rocket is part of the larger suite and is a free solution with more than 100,000 active installations to date. This is one of the most popular go-to choices to control the Heartbeat API settings on a WordPress site.

A full WP Rocket plugin subscription for WordPress costs $49 for a single website. In comparison, the Perfmatters solution comes at $24.95 per year for one site.

How to Limit the Heartbeat API?

To limit the Heartbeat API we have to install the appropriate add-on, in our case – Heartbeat Control from WP Rocket. 

To do this, navigate to the /wp-admin section of your WordPress website. Under the Plugins tab, select the link that states Add New. This should lead to /wp-admin/plugin-install.php.

Next, type Heartbeat Control into the search box under keywords. You should see:

Now, click on the Install Now button to add the plugin to your website. Hit the Activate button on the screen afterward.

You should now see a link under the Settings tab that leads to Heartbeat Control. Click on it to enter the administration section of the plugin. The main control panel looks like that:

The main options here are to allow, disable, or modify the Heartbeat API for the WP Dashboard, Frontend, or Post Editor. Administrators can also configure the settings that best represent the workflow of their publishing community or writers without any complex coding requirements.

How to Stop Heartbeat Completely?

If you prefer not to install a third-party plugin dependency, it is possible to completely disable the functionality of the Heartbeat API in WordPress using a few lines of code in the functions.php file. To use this method, find and edit the functions.php file to include the lines:

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

The advantage of this approach is that it will completely eliminate the CPU activity related to processing the Heartbeat API on active WordPress websites in production. The downside is that you may lose functionality with modules that rely on the service or with multi-user post editing.

Other Heartbeat API Settings

The Heartbeat Control plugin also includes the ability to tinker with the period on which API calls are implemented for the dashboard, frontend, and post editor. This allows you to create custom configurations for the Heartbeat API that preserve functionality while optimizing your WordPress website performance.

The Heartbeat Control plugin includes options to run the API for each service at intervals from 0 to 300 seconds. Experiment with these values to find the right balance for your site.

When Heartbeat might be harmful to your website?

The Heartbeat API is a core WordPress functionality that is designed to harmonize website creation across teams that are using the CMS simultaneously for different workflow requirements. If you have many admin users and open new tabs, the API calls can easily spiral out of control.

That’s why, WordPress administrators need to monitor their usage logs and platform analytics to determine if the site performance is being affected adversely due to the Heartbeat API. Consider regulating the service if you receive too many AJAX POST requests from the /wp-admin/admin-ajax.php file.

Conclusion

The WordPress Heartbeat API is a functional part of the core CMS distribution that can be extended with plugins to deliver update messages to users in real-time. The Heartbeat API is a WordPress admin ajax.php service that you can turn off by adding code to the functions.php file.

You can easily manage the API via the Heartbeat Control plugin from WP Rocket. The add-on also allows you to lower your CPU usage without the need to completely disable WordPress Heartbeat in wp-admin.

ScalaHosting recommends disabling Heartbeat on WordPress sites if you start receiving too many post requests from the admin ajax.php file. You can also limit WordPress Heartbeat API settings with the Heartbeat Control plugin to optimize your website for the best performance.

FAQ

Q: Why would I need to limit WordPress Heartbeat API services on a website?

A: If you have many admin users, content creators, or open tabs on a WordPress website running on shared hosting, updating the WordPress dashboard for data synchronization and collaborative editing can consume many resources. Turning the API off can optimize your CMS performance.

Q: Will turning off Heartbeat API affect WordPress admin or post editor?

A: Core functionalities and third-party plugins that rely on the Heartbeat API will no longer operate if you turn off the service. Some functions might switch seamlessly, but others may generate errors, depending on their underlying code. In such cases, it is easier to limit Heartbeat or modify its timing frequencies to maintain your smooth workflow.

Was this helpful?

What’s your goal today?

1. Find the right Web hosting solution

If you’re looking for industry-leading speed, ease of use and reliability Try ScalaHosting with an unconditional money-back guarantee.

2. Make your website lighting fast

We guarantee to make your WordPress site load in less than 2 seconds on a managed VPS with ScalaHosting or give your money back. Fill out the form, and we’ll be in touch.

Please enter a valid name
Please enter a valid website
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

3. Streamline your clients’ hosting experience

If you’re a web studio or development agency hosting more than 30 websites, schedule a call with Vlad, our co-founder and CTO, and see how we can deliver unmatched value to both your business and your clients.

Photo

Need a custom cluster or professional advice?

Book a meeting and get a free 30-minute consultation with Vlad, co-founder & CTO of Scala Hosting, who will help you select, design and build the right solution - from a single data center cluster to a multi-region & multi-datacenter high availability cluster with hundreds of servers.

Book a free consultation

4. Learn how to grow your website in 2023

An all-star team of SEO and web influencers are sharing their secret knowledge for the first time in years. Learn about the future of SEO, Web Design best practices and the secrets to getting the foundation for your website to thrive. Watch the exclusive webinar.

An Exclusive Insiders Look Behind The SEO and Web Development Curtain

Rado
Author

Working in the web hosting industry for over 13 years, Rado has inevitably got some insight into the industry. A digital marketer by education, Rado is always putting himself in the client's shoes, trying to see what's best for THEM first. A man of the fine detail, you can often find him spending 10+ minutes wondering over a missing comma or slightly skewed design.