WordPress 3.6.0 introduced the Heartbeat API. It’s the backbone to some of the new features such as session management, better revision management, post locking, auto-saving and more. Unfortunately, it also introduced increased CPU usage when logged into the WordPress Dashboard.

The issue lies in the way the Heartbeat API works. When logged in, your browser sends a POST request to wp-admin/admin-ajax.php every 15 seconds when your tab is active and every 120 seconds when your tab is in the background. Since it’s sending a POST request, it’s spawning a new PHP process. This isn’t so much an issue if you have a single tab open but the problem lays for users who like to keep multiple tabs open at a time while logged in to the Dashboard. Take a look at the following POST request data:

Here are where things start getting interesting. This is a one minute sample of the access-logs with eight tabs open total. We can see the active tab (Post-new) sending its normal request every 15 seconds but in addition, the tabs in the background are sending their requests as well. 22 POST requests (and PHP processes) were spawned within a minute. In a 10 minute period, that would equate to 220 POST requests.

If a WordPress has more plugins active and more content, then PHP process will take more time to process, contributing to CPU load time and processes running. This can all cause issues on a shared hosting environment where users can be limited on the number of processes they have open and CPU limits.

How can I fix the issue?

If you’re on a shared hosting platform, then it’s encouraged that you reduce the amount of tabs you have open at a time. If you are finished with making changes in the Dashboard, then log out and close any remaining tabs. If at all possible, work with lesser tabs open.

Is there another way?

Sure, but it’s not one that’s recommended as it involves modifying code and disables features. If you want to go that route, remember to make backups of the files you are changing prior to modifying them. These changes may also not work in the future if WordPress decides to change something. Disabling polling may also break some functionality of WordPress features or ones that plugins depend on. Any changes you make are of your own responsibility.

Some of the features this breaks includes editing Categories while editing posts, adding/editing tags, autosaving and other features added by plugins.

There are three ways to disable admin-ajax.php:

Disabling Heartbeat everywhere

Disabling Heartbeat just in the Dashboard

Disabling Heartbeat everywhere except when editing posts.

First, locate your active theme’s functions.php. For instance, if you are using TwentyTwelve, then the file will be in:

wp-content/themes/twentytwelve/functions.php

Make a copy of the file to create a backup of it. You can append -bak to the end of the file.

Modify the original functions.php and add the code towards the top, after the opening <?php tab. These are the code options depending on what you want to disable. Do not add all three, simply choose one: