Having trouble with your hosting resources? Limit Heartbeat in WP
Posted: Wed Jan 29, 2025 4:55 am
As WordPress site developers at Entrebits we have the healthy habit of stopping the WordPress Heartbeat function . This often means a drastic reduction in the execution of admin-ajax.php, which is nothing more than the file that runs the WordPress administrator, also known as the backend . Let's start by learning more about Heartbeat and its problems.
What is Heartbeat?
The Heartbeat was introduced in WP 3.6 and its main function is to lock the editing of the content that is currently being edited by a user and provide real-time information through the dashboard. It is really useful if there are several people working on the same website. Let's suppose that we have an online store and there are two managers, the manager jordan number dataset the order to increase the stock of a product, the two store managers enter Woocommerce and modify it at the same time, this can create conflicts, since the information of the last manager who enters will overwrite that of the first. The lock is represented as a padlock next to the entry, page or product in case you have Woocommerce to edit.
Other CMS like Joomla! have the blocking option, but in this case it is a bit more particular. WordPress introduces a temporary block , every 15 seconds it checks if there is any content being edited and who it is attributed to. When the editing stops, the block disappears on its own. It generates a POST request similar to the one in the following graph -in this case every 60 seconds-. This consumes resources, which is equivalent in many hostings to one visit every 60 seconds. In the graph we see that there is only one visit to the site, in green, the rest are all Heartbeat requests.
Of course this consumes RAM, CPU and server executions, if you have many visits, the sum of WordPress Heartbeat plus the views and robot crawling may shoot up your hosting account, so it is advisable to be prepared, optimize the execution of Heartbeat , let's get to the point.
Some hostings like Siteground offer you the possibility to know which scripts are being executed. This information is very useful to know if the Heartbeat control is working. In this account the executions of index.php and admin-ajax.php were similar, after controlling Heartbeat the executions of admin-ajax are practically testimonial. This saves a large amount of resources and executions on the server.
Optimizing Heartbeat via your theme's functions.php file
Optimizing Heartbeat in WordPress is very simple and takes just a few minutes. Depending on your knowledge, you can do it in two ways: through a code in functions.php or through a plugin that will add the same code on its own.
To optimize through functions.php we must locate the folder of our template which must be located in public_html/wp-content/themes/yourtemplate. To access it you can use an ftp client like Filezilla or if you have CPANEL or FTPWeb, browsing through the file manager. If you do this, you will reach the set of files of your template where we find functions.php
We recommend that you make a backup copy of your functions.php file before making any changes. If something goes wrong, you can simply delete the modified file and re-upload the original. To make a copy, download the file to your computer. To edit it, if you are in CPANEL, you can edit it by right-clicking on it and clicking Edit . If you are in FTP, you will need to download the file, edit it with a code editor such as Notepad++, and upload it back to the server. Once we know we have located the file and know how to edit it, we can add the code. To deactivate it, you will need to add the following code:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
This will completely stop Heartbeat. If you are hosted on SiteGround you can see how the executions of admin-ajax.php will plummet if you are not working with the admin. If you are on another hosting we invite you to check the CPU and memory usage statistics.
Optimizing Heartbeat via the Heartbeat Control plugin
Before you start, it is very important to do one thing or the other. If you add the code to functions.php and activate Heartbeat Control you run the risk of your template failing. In any case, if you receive an error, just deactivate the plugin, since this plugin will never prevent you from accessing the WP administrator when modifying a template file . After this recommendation, let's get started!
You can go to the official WP repository and download the plugin or directly request it from the WordPress administrator. You will see that it has not been updated for two years, no problem, it is such a stable WordPress feature that it has not really required updates . We search for it and click on Install Now.
What is Heartbeat?
The Heartbeat was introduced in WP 3.6 and its main function is to lock the editing of the content that is currently being edited by a user and provide real-time information through the dashboard. It is really useful if there are several people working on the same website. Let's suppose that we have an online store and there are two managers, the manager jordan number dataset the order to increase the stock of a product, the two store managers enter Woocommerce and modify it at the same time, this can create conflicts, since the information of the last manager who enters will overwrite that of the first. The lock is represented as a padlock next to the entry, page or product in case you have Woocommerce to edit.
Other CMS like Joomla! have the blocking option, but in this case it is a bit more particular. WordPress introduces a temporary block , every 15 seconds it checks if there is any content being edited and who it is attributed to. When the editing stops, the block disappears on its own. It generates a POST request similar to the one in the following graph -in this case every 60 seconds-. This consumes resources, which is equivalent in many hostings to one visit every 60 seconds. In the graph we see that there is only one visit to the site, in green, the rest are all Heartbeat requests.
Of course this consumes RAM, CPU and server executions, if you have many visits, the sum of WordPress Heartbeat plus the views and robot crawling may shoot up your hosting account, so it is advisable to be prepared, optimize the execution of Heartbeat , let's get to the point.
Some hostings like Siteground offer you the possibility to know which scripts are being executed. This information is very useful to know if the Heartbeat control is working. In this account the executions of index.php and admin-ajax.php were similar, after controlling Heartbeat the executions of admin-ajax are practically testimonial. This saves a large amount of resources and executions on the server.
Optimizing Heartbeat via your theme's functions.php file
Optimizing Heartbeat in WordPress is very simple and takes just a few minutes. Depending on your knowledge, you can do it in two ways: through a code in functions.php or through a plugin that will add the same code on its own.
To optimize through functions.php we must locate the folder of our template which must be located in public_html/wp-content/themes/yourtemplate. To access it you can use an ftp client like Filezilla or if you have CPANEL or FTPWeb, browsing through the file manager. If you do this, you will reach the set of files of your template where we find functions.php
We recommend that you make a backup copy of your functions.php file before making any changes. If something goes wrong, you can simply delete the modified file and re-upload the original. To make a copy, download the file to your computer. To edit it, if you are in CPANEL, you can edit it by right-clicking on it and clicking Edit . If you are in FTP, you will need to download the file, edit it with a code editor such as Notepad++, and upload it back to the server. Once we know we have located the file and know how to edit it, we can add the code. To deactivate it, you will need to add the following code:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
This will completely stop Heartbeat. If you are hosted on SiteGround you can see how the executions of admin-ajax.php will plummet if you are not working with the admin. If you are on another hosting we invite you to check the CPU and memory usage statistics.
Optimizing Heartbeat via the Heartbeat Control plugin
Before you start, it is very important to do one thing or the other. If you add the code to functions.php and activate Heartbeat Control you run the risk of your template failing. In any case, if you receive an error, just deactivate the plugin, since this plugin will never prevent you from accessing the WP administrator when modifying a template file . After this recommendation, let's get started!
You can go to the official WP repository and download the plugin or directly request it from the WordPress administrator. You will see that it has not been updated for two years, no problem, it is such a stable WordPress feature that it has not really required updates . We search for it and click on Install Now.