WordPress Heartbeat – Ugh – Disabling it

You know, I really liked the whole idea of getting those automatic saves in there with WordPress when they released it. And for the most part, it works really well. Now, I’m not going to claim to be an uber-genius on the inner-workings of WordPress. That really is NOT my focus. I’m more on the marketing side of it, but have occasional dalliances into the guts. This particular feature though, I have not dallied into – until yesterday.

After nothing but issues with one of my servers, the tech people sent me graphs, charts and all sorts of info. The thing that I saw a lot of was traffic, calls and memory load to the admin-ajax.php page. So what IS that page? In short, any time an ajax call is made, this is the page that handles it. So, if you have an ajax-laden site or functionality, this page is going to get whole lot of usage.

Right off the bat, I can tell you that the heartbeat functionality in WordPress makes serious use of this page. What is the heartbeat function? It’s the thing that autosaves your work while you’re in the website. Helpful, but no necessary. we’re going to examine this usage in a couple sites and likely post our findings here.  The one thing that I have seen a lot of is high HIGH activity on ThemeForest themes.  The one thing that they seem to have in common is that they all have everything including the kitchen sink included in them. So there may be more to it than just the heartbeat thing, but…

BUT, How to disable the heartbeat? Read on.

Disable WordPress “Heartbeat”

So here is something that was introduced not too long ago in WordPress – and the topic of this article – WordPress Heartbeat. This has caused me problems in several cases. Not all themes seem to be so annoying with autosave functions, but I have specifically noticed the themes that I have gotten from ThemeForest in particular (3 of them) all seem to be pretty hard on on autosaving and every time I go to save something, I see that annoying little wheel spinning by itself and the button grayed out. Nice feature, but you know what? I lived without this functionality for quite a while and if it’s going to take my server out with it’s interminable autosaves, I don’t need it.

Here’s how to disable heartbeat completely. Find the functions.php file for your THEME and place this right at the top.

UPDATE: Aug 7, 2014

ACCCKKKKKK!  The solution that I was using here was actually disabling a few functions at least for one customer. If you have implemented a solution and you can no longer use tags or quickedit is not working, then that’s what that customer was experiencing.  I’m removing that which WAS here and planting a new piece of code to be used in the functions.php of your theme (at the top).

*Update: Aug 7, 2014 A – found that Gravity Forms hosed up with the lastly current code. Added the admin.php page into the “don’t kill it off here” conditional. Life again back to good. Heartbeat and gravity forms – yeah buddy.

<code>function my_deregister_heartbeat() {
	global $pagenow;

	if ( 'post.php' != $pagenow &amp;&amp; 'post-new.php' != $pagenow &amp;&amp; 'admin.php' != $pagenow ) {
		wp_deregister_script('heartbeat');
		wp_register_script('heartbeat', false);
	}
}
add_action( 'admin_enqueue_scripts', 'my_deregister_heartbeat' );</code>

and now back to our regularly scheduled post…

What IS happening on each of my pages?

Now before you go crazy killing off heartbeat everywhere, it might be a good idea to verify that IS the actual culprit. Want to see what’s going on with each page when you load it up? Install THIS plugin and get some insight. I wanted to break down my page and see what the heck was going on with memory usage, query loads and all – very helpful.

http://wordpress.org/plugins/query-monitor/

Which plugins call the admin-ajax.php page?

This needs to be done in SSH mode in the plugins directory – supposedly. I have NOT tried this yet as I’m not a real genius with SSH or Linux for that matter. I use it, but I speak Windows far more fluently. WILL be trying this in the near future to hunt down the calls to admin-ajax.php stuff! Naturally, I found this, copied it out so I would NEVER lose it again and intended on giving a link to the original – and the cat shut down that window for me. Thanks critter. Can’t find it again right now and need to move on to bigger things. Here it is. I believe all that’s needed is to run this in SSH in the plugins directory.

find . -name '*.php' -type f -print0 | xargs -0 fgrep admin-ajax.php --

My Final Take on Heartbeat – Aug 7, 2014

You know, when heartbeat came out, I thought it was truly something. And it is truly something – but that something isn’t good in a lot of cases. I’ve had my big boy server hammered hard by this sitting there with 6 XEON cores. I’ve had smaller shared hosting accounts shut down now NUMEROUS times – probably a dozen – due to the heartbeat API. Where previously no problems existed, I’m forever worrying about exceeding my CPU resources on all servers. And the benefit? To ME, it’s negligible. I’m an old time coder and I’m used to saving my work when I have enough where losing it would be a problem. If you’re NOT that kind of person, take words of advice from an old time coder. Save early, save often. And get rid of the heartbeat API.

WordPress Development, are you listening? DITCH the heartbeat api or at least give it to us as a “Please enable Heartbeat functionality” checkbox that we can use based on our own levels of need. Excessive resource usage is just not needed for the minimal functionality improvement that I am seeing. I could be wrong about the level of functionality that is being provided, but before heartbeat blowing out my servers, I was pretty happy with WordPress anyway.

Author: Eric Erickson

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *