The purpose of this API is to simulate bidirectional connection between the browser and the server. Initially it will be used for autosave, post locking and log-in expiration warning while a user is writing or editing.
The idea is to have a relatively simple API that sends XHR requests to the server every 15 seconds and triggers events (or callbacks) on receiving data. Other components would be able to “hitch a ride” or get notified about another user’s activities.
In the future this can be used to block simultaneous editing of widgets and menus or any other tasks that require regular updates from the server.
Introduced in WordPress 3.6 the WordPress Heartbeat API allows WordPress to communicate between the web-browser and the server. It allows for improved user session management, revision tracking, and auto saving.
The WordPress Heartbeat API uses /wp-admin/admin-ajax.php to run AJAX calls from the web-browser. Which in theory sounds awesome, as WordPress can keep track of what’s going on in the dashboard.
However this can also start sending excessive requests to admin-ajax.php which can lead to high CPU usage. Anytime a web-browser is left open on a page using the Heartbeat API, this could potentially be an issue.
How To Fix Issue
Installing the Heartbeat Control plugin
- First, log into your WordPress admin dashboard.
Within your dashboard, hover over Pluginsand click on Add New.
- On this page, enter Heartbeat Control into the search box At the top and press the Enterkey on your keyboard to perform the search.
As you have searched for the exact name of the plugin, it should be the first result that appears. To install it, click on the Install Nowbutton.
WordPress will now handle the download and installation of the Heartbeat Control plugin. Of course, be sure to click on Activate Pluginwhen complete.
Configuring the Heartbeat Control plugin
Now that you have the Heartbeat Control plugin installed, you will need to configure its settings. To access the settings page, hover over Tools on the left side menu bar and click on Heartbeat Control.
- Once on the settings page, you will notice 2 different dropdown boxes. The first box will allow you to disable the WordPress heartbeat on the entire site or on specific locations. Depending on your needs, you may disable the WordPress heartbeat completely, or only allow it on specific locations such as on the post edit page.
The second box allows you to determine how often the WordPress heartbeat API will make a request. For example, on post edit pages it makes a POST request every 15 seconds. This can be modified within the heartbeat frequency dropdown to delay it up to 60 seconds between requests which would cut down server resources caused by admin-ajax requests by 75%.
- Once your changes are made, click on Save Changes.