How to Reduce Admin Ajax Server Load in WordPress

Today we will show you, How to reduce admin Ajax server load in WordPress. WordPress Heartbeat API was introduced in WordPress 3.6. The WordPress Heartbeat API uses wp-admin/admin-ajax.php to run AJAX calls from the browser. The purpose of this API is to improve user session management, auto saving, revision tracking. It sounds amazing, but it also has disadvantages that can also cause high CPU usage and crazy amounts of PHP processes. For example, if you leave your dashboard open it will keep sending POST requests on a regular interval, hence can cause the Heartbeat API to continually spawn PHP processes which uses CPU.

You can disable it completely by adding the following to your working themes function.php file by adding this after the “<?php” tag:

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

But, this is not a good option, as now many plugins are using the heartbeat API, if you completely disabled it, then your site will have issues because the plugins won’t work properly.
Another option is to use Heartbeat Control plugin. With this plugin you can decrease the interval, only run it on post edit pages, disable it everywhere, and disable it on dashboard page.

How to install Heartbeat Control plugin

  • Log in to your WordPress Admin Dashboard and navigate to Plugins menu on the left side > Add new. Search for ‘Heartbeat’ plugin using the available search field in the upper right corner and click on the Install Now button next to Heartbeat Control
  • Once the plugin is installed, hit Activate button to activate it.
  • After the activation, go to Settings > Heartbeat Control Settings menu
  • In the Heartbeat Behavior drop-down choose Modify Heartbeat. And, Select all Locations, and in the Frequency slider choose 60 or more. Click Save Changes.

You can also choose to Disable Heartbeat in the Heartbeat Behavior drop-down and use it for all Locations. But, as previously explained, this is not a good option, as it can disrupt your site functionality.

If you think decreasing the heartbeat interval is not enough, you can make some test to see which plugin is using heartbeat API more frequently.

How to check if a plugin is using admin-ajax.php?

Deactivate all plugins
Make a test of your website here: https://tools.pingdom.com
Check the query for admin-ajax.php
If you don't see the admin-ajax.php in the query, you can try reactivating a plugin
Make another test there, repeat with the next plugin

You can also check it without deactivating the plugins.

Open your website using Chrome
Right click on the page and choose Inspect Element.
Click on Network tab, refresh your page
In the console, you can see "Filter" search box (under red dot), type admin-ajax there then enter
Select one and check the information
You will find some clues as to which plugin generates the request. The result often includes a reference to the related plugin.

When you finish with the searching, you will have enough information on which plugin that calls admin-ajax.php more frequently.
You will want to consider replacing the plugin with another similar one to reduce the CPU load.

Of course you don’t need to reduce admin Ajax server load in WordPress, if you use one of our Linux Cloud  VPS Hosting services, in which case you can simply ask our expert Linux admins to reduce admin Ajax server load in WordPress, for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to reduce admin Ajax server load in WordPress, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks

 

Leave a Comment