List of content you will read in this article:
WordPress is quite a versatile and feature-packed platform that makes use of many technologies to provide convenience and ease of use for its users. One such technology is the WordPress Heartbeat API. Introduced originally in 2013, it allows your browser to automatically communicate with the server.
Today, we will give a small introduction to the Heartbeat API and show you how to install and manage it on your WordPress installation.
What is WordPress Heartbeat API?
The WordPress Heartbeat API is a great feature that provides real-time communication between the server and the browser when you are logged into your WordPress admin panel. It uses the file /wp-admin/admin-ajax.php to run AJAX calls from the browser. By default, AJAX requests are sent every 15 seconds on post edit pages, and every 60 seconds on the dashboard.
This is indeed helpful, however, if you leave your WordPress admin open for long periods (for example when you write or edit posts), the AJAX requests from the API can pile up and generate high CPU usage, leading to server performance issues and even hosting account suspensions.
With Heartbeat Control by WP Rocket, you can easily choose to limit or completely stop the activity of the WordPress Heartbeat API. You can also add rules for specific locations (e.g. dashboard, frontend, or post editor).
How to install the Heartbeat Control plugin for WordPress:
Follow these simple steps in order to install WordPress Heartbeat API on your system:
Step 1: Log in to your WordPress administration dashboard and using the left sidebar
Step 2: Navigate to Plugins > Add New.
Step 3: Search for "Heartbeat Control", then install and activate the plugin from the list of results.
Step 4: In the left sidebar, click Settings > Heartbeat Control Settings, to configure the plugin.
The Heartbeat Control plugin allows you to create one or more rules to modify how the WordPress Heartbeat API works. This includes the ability to fully disable the API. Bear in mind that the API is used for a variety of functions (for example, allowing only one author to edit a post at a time) alongside a range of under the hood features that will be disabled if you completely switch it off.
Rules are prioritized by the order they appear on the screen. Rules closer to the top of the screen have priority over those towards the end.
Under Rule 1, click the Heartbeat Behaviour dropdown menu and select whether you want to allow, disable or modify Heartbeat.
In this example, we’ll select Modify Heartbeat.
Under Locations, the checkboxes allow you to target the rule to specific areas of WordPress. The WordPress Dashboard, Frontend, and Post Editor are available for selection, along with a Select/Deselect All button to toggle the selection of all locations.
Click and drag the Frequency slider to a value of your choosing (in seconds). Moving the slider all the way to the right will delay the Heartbeat for 5 minutes (i.e. 300 seconds). You may need to fine-tune the Frequency after the rule has been created to achieve a balance between performance and functionality.
Click Save Changes to complete the configuration or Add Another Rule to continue tweaking Heartbeat settings. The arrows at the bottom of the screen allow you to change the priority of rules in the list.
That's all you need to know in order to modify the behavior of the WordPress Heartbeat API. Nevertheless, this is just one way you can minimize resource usage on your server and improve your WordPress website's performance. Look through our extensive knowledgebase to find out many more tips on how to optimize your site.