The WordPress Heartbeat API is a server polling tool integrated into WordPress, designed to facilitate near-real-time updates on the frontend. This API operates by making AJAX calls through the admin-ajax.php file. However, if you observe an unusually high volume of POST requests directed at this file, it may indicate that you need to reduce the frequency of the WordPress Heartbeat API or consider disabling it entirely.
Excessive requests to admin-ajax.php can significantly increase CPU usage on your server, potentially leading to performance issues. To completely disable this functionality and prevent it from contributing to the overall CPU time and the number of executions on your website, you can insert specific code into your site.
Go to the functions.php file of your WordPress theme and paste these lines right after the opening <?php tag:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
How to Restrict WordPress Heartbeat
If you prefer not to disable the Heartbeat API entirely, you can opt to limit its execution frequency instead. This can be accomplished using a plugin like Heartbeat Control. After installing and activating the plugin, you can adjust the Heartbeat API frequency to intervals of 60 seconds or more. It's advisable to set the Heartbeat locations to "Allow only on post edit pages" to further reduce unnecessary server load.
By properly managing the WordPress Heartbeat API, you can optimize your site's performance and prevent excessive resource usage, ensuring a smoother experience for both administrators and users.
And that’s it! With these steps, you can effectively control how WordPress Heartbeat operates on your website.