What is The Heartbeat API?
WordPress introducted heartbeat API in WordPress 3.6, which allows WP to communicate between the browser and the hosting server. It's responsible for user session managament, revision tracking and auto saving. However in most cases, heartbeat API can lead to an increase in your CPU/memory usage and slow down your website. If your WordPress install is using too many resources and you see /wp-admin/admin-ajax.php as the culprit, it’s because of the Heartbeat API.
In this article, we will show you how to limit Heartbeat API in WordPress or completely disable it.
How Heartbeat API works in WordPress
The Heartbeat API uses /wp-admin/admin-ajax.php to run AJAX calls from the web-browser. If you watch the server requests while using post editor, you will see POST /wp-admin/admin-ajax.php "http://yourdomain.com/wp-admin/index.php appear every 15 seconds. If the heartbeart request takes 30 seconds or longer, WordPress will display a connection error and reattempt the connection to the server.
This can quickly turn into an a problem everytime your web browser is left open on any WordPress page using the heartbeat API, the heartbeat API starts to send excessive requests to admin-ajax.php which leads to high CPU usage.
How to limit the HeartBeat API in WordPress
- Login to your WordPress dashboard
- From the dashboard navigation menu select Plugins > Add New
- Type Heartbeat Control into the search box and press Enter to search.
- Click Install now beside the Heartbeat control plugin
- After the plugin is installed, click Activate Plugin
- Find plugin settings Under Settings > Heartbeat Control
- Change control heartbeat locations to "Allow only on post edit pages"
- Change Override Heartbeat frequency from the dropdown to 60 seconds
- Saves changes