Heartbeat API NOT disabling

I’m hoping this is something easy to fix although from my tests (very new to WordPress so please go easy with me if these tests are not very good!) doesn’t appear to be.

I have a site hosted on SiteGround which was eating through the CPU seconds like nobody’s business.

I’ve now managed to put it down to the Heartbeat API calling the admin-ajax.php file so much.

Small question about admin-ajax.php if I may? Am I correct in my thinking that this file is only ever fired if someone is actually logged into the control panel and not under any other circumstances such as someone just visiting the site?

To that end I found some code on the internet which is shown below :

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

I read that this goes into the functions.php file of my theme at the very top after the opening ? tag.

I’ve placed it there however I’m fairly certain that the Heartbeat API is still running despite this.

Am I correct in my thinking that the Heartbeat API is what is responsible for when one user is editing a post and another user tries to edit it and they get a message warning them someone else is already editing that post?

If so then I am still getting those messages even with this code in place and with two completely different users on 2 completely different browsers.

I’m testing this on a localhost machine as don’t want to mess with the live site currently however this is a completely vanilla install of WordPress 4.8.1 with absolutely no plugins or custom themes being used. Just the standard 2017 theme.

So my questions would be :

1 – Is it even possible to turn off the Heartbeat API or is it a known issue that it actually can’t be turned off?

and

2 – If it definitely can be turned off then what am I doing wrong?

Thanks for any help with this.

Best wishes,

Mark

Topic heartbeat-api Wordpress

Category Web


Am I correct in my thinking that this file is only ever fired if someone is actually logged into the control panel and not under any other circumstances such as someone just visiting the site?

No, Ajax API is used for arbitrary requests, including those for the front–end and non–authenticated users.

Am I correct in my thinking that the Heartbeat API is what is responsible for when one user is editing a post and another user tries to edit it and they get a message warning them someone else is already editing that post?

While Heartbeat API was implemented for such functions, it's more of a generic channel arbitrary things can run on top of.

Is it even possible to turn off the Heartbeat API or is it a known issue that it actually can’t be turned off?

As far as I remember it is exceptionally hard to disable, more so in clean and compatible way. It also went through several approaches, so a lot of related snippets online are outdated and irrelevant. If there is a sane way to turn it off as of right now — I am not aware of it.

If it definitely can be turned off then what am I doing wrong?

Not sure if you do anything wrong. This might be better discussed with hosting support. Might be something is messing it up, might be your needs (such as many logged in users in admin) are larger than your plan. Anecdotally I am long time SiteGround user myself and never had Heartbeat API issues with them.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.