What is WordPress heartbeat and how to deal with admin-ajax.php usage

You may have noticed, that when you have the WordPress dashboard open in multiple tabs, the CPU load in your cPanel account suddenly increases.

If you monitor the requests on the server when WordPress editor is opened, you’ll see such requests appear every 15 seconds. This is the pulse generated by the API:

[00:10:30] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:10:45] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:11:00] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:11:15] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:11:30] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:11:45] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0
[00:12:00] nctest.info POST /wp-admin/admin-ajax.php HTTP/1.0

The script admin-ajax.php (the so-called WordPress heartbeat) extends the user's WordPress session for the easier use of the administrative panel. If the administrator or the editor works with the site often, it eliminates the need to enter the login / password each time.

When editing an entry, WordPress executes the AJAX request every 15 seconds, i.e. to achieve 1 query per second on the server, you need 15 open editors.

In many cases, admin-ajax.php is responsible for increased Physical memory and CPU consumption due to the frequent (every 15 seconds) database calls along with other requests. Since admin-ajax.php is dynamic (it can not be cached), it directs all requests right to the server, creating a significant load.

One of the best ways to decrease the load on the account is to use WordPress Heartbeat API plugin. With the help of this plugin, you can control the frequency of AJAX calls.

NOTE: Before proceeding with any changes, make sure that you generate a full backup of your website. If you've created your site using Softaculous script installer, feel free to refer to this guide as well.

1. Log in to the WordPress Admin Dashboard and navigate to Plugins menu > Add new. Search for 'Heartbeat Control' plugin using the Search field in the upper right corner and click on the Install Now button next to Heartbeat Control by WP Rocket:

2. Once the plugin is installed, hit Activate button:

3. After the activation, go to Settings > Heartbeat Control menu:

4. In the General settings tab check-mark the Modify Heartbeat options. Then, Select all Locations and in the Override Heartbeat frequency sliders choose 60 or more. Click Save Changes.

You can also choose to Disable Heartbeat in the General settings tab and use it for all Locations. This way you will disable the use of the Heartbeat functionality on all of your pages.

NOTE: By disabling Heartbeat completely, you may disrupt the functionality of some features in WordPress. If this occurs, you can adjust the Location settings or just enable Heartbeat back and set the higher Frequency.

We have explained how you can modify heartbeat frequency for your website, however, if you are the only editor on your site, and the requests for admin-ajax.php from your IP address are more than 1 per second, then it is worth figuring out the reason of it.

The most common reason for this behavior is the theme or a plugin. You can deactivate them all and enable one-by-one in order to find the source. It's worth mentioning disabling Heartbeat with the Heartbeat Control plugin in such cases will only temporarily hide the problem rather than fix it.

That's it!

Need any help? Contact our HelpDesk

29827 times

Need help? We're always here for you.