• I found a couple of closed posts here and several links online regarding this, but none of the solutions have worked for me so far.

    I’m on shared hosting and running a small, private Buddypress site.
    Everything was fine until it one day it was not and I found that my site slowed down to the point that it is pretty much unusable.

    I did all the usual things to try to speed it back up, such as optimizing my wordpress install and data base, I disabled all of my plug-ins and tested them one by one etc. Finally I contacted my hosting company thinking perhaps there was a server issue. I was essentially informed that there was a process on my domain which was running so aggressively that it was negatively impacting my site functionality. Turns out the problem was due to the wordpress Heartbeat api.

    I really don’t need or want it running, but I can’t for the life of me seem to get it to stop or even slow down to a reasonable number of requests.

    I’ve tried adding the suggested code to my theme’s function.php file, or to the wordpress plugins.php file to no avail.

    Has anyone found a way to control this function successfully? I really need help with this because my site is being rendered useless.

Viewing 5 replies - 1 through 5 (of 5 total)
  • There’s actually a plugin that is supposed to help, but I’ve never used it:
    https://www.ads-software.com/plugins/ajax-heartbeat-tool/

    Thread Starter bluesybil

    (@bluesybil)

    Thank you for your suggestion, but it generated a fatal error upon activation for some reason.

    Gal Baras

    (@galbaras)

    If the code you’ve added is similar to what I’ve found, you may need to tweak it a bit. Here’s what I’ve seen:

    function stop_heartbeat() {
    	global $pagenow;
    
    	if ( $pagenow != 'post.php' && $pagenow != 'post-new.php' ) {
    		wp_deregister_script('heartbeat');
    	}
    }
    add_action( 'init', 'stop_heartbeat', 1 );

    Try this:

    • Make sure that BuddyPress pages have $pagenow set.
    • Change the priority of your action to something higher, e.g. 999
    • Attach the action to ‘wp_head’, instead of ‘init’, because it happens later

    Also, I’ve found that the heartbeat API seems to be required for managing featured images ??

    I read somewhere that this code needs to be placed at the very top of functions.php, right after the opening <?php for it to work…

    Is that corect?

    No, because functions.php is executed completely before the “init” actions are triggered.

    Just to let everyone know, I found out that in my case, disabling the heartbeat API caused all kinds of problems and I stopped doing it.

    Instead, I found out that shared hosting was configured with no opcode caching for PHP, which means that PHP must compile the code every time from scratch, which is what takes most of the time.

    Assuming this is possible with your hosting platform, follow the instructions here to enable the “opcache” option.

    With opcode caching turned on, compiled PHP code will be saved and reused, so your site will speed up 3-fold. If your site’s been hitting the hosting account’s processing limits and thrashing, that’ll go away.

    Cheers,
    Gal

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Attempting to disable Heartbeat API’ is closed to new replies.