WordPress Heartbeat API and How to Control It

WordPress introduced a feature called Heartbeat API in version 3.6, which is a simple server polling API that uses Admin-Ajax to obtain near-real-time frontend updates.

What it basically does is to continuously connect to the server at a fixed interval between 15 to 60 seconds (called a “tick”, thus the name heartbeat) to retrieve the latest data even if you did you reload the page.

The Heartbeat API is involved with these operations of your WordPress website:-

  • Autosave and Revisions of your Posts and Pages
  • Post-locking notifications if another editor is editing the post
  • Notifications in the WordPress Admin
  • Real-time data of eCommerce plugins

What is the problem?

While this sounds good on theory, what usually happen is as your website gets heavier and as more plugins are hooked on to the API, you will quickly experience high CPU usage as a result of the continuous and multiple connections to the server.

This is manifested in the form of multiple PHP processes like /wp-admin/admin-ajax.php which can eat up your precious CPU resources.

What can be done about it?

Ideally you can just disable the WordPress Heartbeat API to stop the admin-ajax.php connections altogether.

However, reality is a usually not that simple as some of your plugins and/or themes may break if you disable WordPress Heartbeat API completely with many of them come to rely on the API for some of their operations.

As such, what you should do instead is to control the “tick” interval so it doesn’t connect to the server too frequently. There are multiple plugins in the WordPress repository like the Heartbeat Control plugin which does exactly that.

If you are a NoFrillsCloud client, you don’t have to install yet another plugin as the LiteSpeed Cache for WordPress plugin can control the Heartbeat API for you.

All you need to do is to head over to your WordPress Admin > LiteSpeed Cache plugin > Toolbox > Heartbeat tab.

From there you should enable Frontend Heartbeat Control, Backend Heartbeat Control and Editor Heartbeat.

The “Recommended value” are actually the default value set by WordPress so we recommend setting a number above that. For the most optimal setting, set them to 120 seconds.