How To Set Frequency Of WordPress Heartbeat And Limit Executions?
The WordPress Heartbeat API was introduced with the release of WordPress 3.6. When you are logged into the WordPress admin panel, WordPress Heartbeat API allows your browser and the server to communicate. WordPress can now handle a number of tasks thanks to this capability, such as informing other authors when a specific post is being modified by another user, allowing plugins to employ script executions to send you real-time notifications, etc.
Even though the WordPress Heartbeat API looks like a great feature, it might cause some issues in some situations. The Heartbeat makes checks at different time periods on different pages of your website – like for the post edits, it makes a check in every 15 minutes and on the Dashboard, the check is made every minute etc. Every ‘tick’ made by the Heartbeat creates a POST request that adds to the number of your executions and it also adds to the CPU time used.
The WordPress Heartbeat feature makes use of the wp-admin/admin-ajaz.php file in order to make the AJAX calls. If you notice that a large number of POST requests are generated by that file, it means that you have to limit the work of Heartbeat or you need to stop it completely.
How To Limit Heartbeat?
It is possible to limit the execution frequency of WordPress Heartbeat. This can be done by making use of a plugin known as ‘Heartbeat Control’.
- Install the Heartbeat Control plugin and activate it
- Now go to ‘Settings’ and click on ‘Heartbeat Control Settings’
- From the ‘Heartbeat Behavior’ drop down menu, select ‘Modify Heartbeat’
- Select all the ‘Locations’
- From the ‘Frequency’ slider, select 60 or above
- Save the settings
When the settings are saved, you will override the Heartbeat execution frequency that is set by default. The frequency will be set to the value that you set through the Frequency slider.
How To Disable Heartbeat?
You can disable WordPress Heartbeat by selecting the option ‘Disable Heartbeat’ from the ‘Heartbeat Behavior’ drop down menu and enable all the ‘Locations’. This will disable the use of Heartbeat feature on all the pages of your website.
How To Stop Heartbeat Completely?
If you no longer wish to work with the WordPress Heartbeat feature, you can stop it completely. For doing this, you have to edit the ‘functions.php’ file of your theme and paste the lines mentioned below right after opening the ‘<?php’ tag:
add_action( ‘init’, ‘stop_heartbeat’, 1 );
function stop_heartbeat() {
wp_deregister_script(‘heartbeat’);
}
This will completely stop Heartbeat from working on your website and it will no longer add to the number of executions and the CPU time utilized for your account.