Admin-Ajax Eating Up CPU

I thought I’d pass along this important piece of information about a problem I encountered with admin-ajax.php.  This is not necessarily new information but if you searched for this and are having the problem you’ll be happy to have an answer like I was.

So the problem that was occurring was that admin-ajax.php was taking up 70% or more of cpu on the server. That was causing the server and it’s site to respond slowly.   If you’re a host, that’s a problem because it affects more than one customer. If you’re a site owner you’re in this boat because the host is probably shutting you down.  Either way, let’s take a quick look at what it is and how to solve it.

Admin-ajax.php. What it does.

Admin-ajax.php is associated with the heartbeat api for WordPress.  It keeps track of what’s going on in the dashboard and helps with sessions and saving drafts, etc. However, you can disable it to solve your issue.

This bit of code below when added to your functions.php file will solve your issue. At least it did for mine.
add_action( ‘init’, ‘my_deregister_heartbeat’, 1 );
function my_deregister_heartbeat() {
global $pagenow;

if ( ‘post.php’ != $pagenow && ‘post-new.php’ != $pagenow )
wp_deregister_script(‘heartbeat’);

 

I hope this helps you.