fbpx

How to Limit WordPress Heartbeat To Lower Execution Numbers

heartbeat picture

WordPress 3.6 introduced the WordPress Heartbeat API – it allows your browser to communicate with the server when you’re logged into the WordPress admin panel. This functionality allows WordPress to handle things like showing other authors that a post is being edited by another user, plugins can hook up to those “ticks” and show you notifications in real-time, etc.

 

However, even though this is great functionality it may cause issues in certain cases. On different pages, Heartbeat makes checks on different periods – on post edit, it makes it every 15 seconds, on your Dashboard – every minute, etc. Each “tick” generates a POST request which adds to the number of your executions and CPU time used.

 

The API uses the /wp-admin/admin-ajax.php file to make AJAX calls. If you notice a significant amount of POST requests by that file, this means that you need to limit the work of Heartbeat or stop it completely.

how to stop heartbeat completely

Usually, you can completely disable it if you’re the only person working at any given time on your site and you know that you don’t have any important functionality that heavily relies on it to work properly.

 

To disable it, go to the functions.php file of your theme and paste these lines right after the opening <?php tag:

 

add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

 

This will completely disable this functionality and it will no longer add to the executions number and CPU time used in your account.

how to limit heartbeat

If you don’t want to stop Heartbeat completely, you can simply limit the execution frequency. You can do this by using a plugin called Heartbeat Control.

 

Simply install it by following the instructions in our tutorial on How to Install WordPress Plugins and activate it. Then go to Settings -> Heartbeat Control and from the Override Heartbeat frequency dropdown choose 60 seconds. Finally, save the settings and that’s it.

heartbeat control wordpress

If you want to, you can set heartbeat to work from different locations only – like on your post and edit pages for example.

Heartbeat Control

That’s it, WordPress Heartbeat is now tamed and should not be adding to the number of executions and CPU seconds used when you forget a dashboard tab open.

Share:

More Posts