WordPress.org

Support

Support » How-To and Troubleshooting » Admin-ajax.php being Called from Admin Pages Causing DB Connection Issues

Admin-ajax.php being Called from Admin Pages Causing DB Connection Issues

  • optimized-marketing

    @optimized-marketingcom

    Here is some back story, my webhosting shut all my sites down because admin-ajax.php was creating DB connections and sleep for long periods of time. The highest sleep time I saw was 45s. What I determined is that in one of the WP updates, from WP 3.5 to WP 3.7.1, admin-ajax.php started being called from multiple admin pages (/wp-admin/widgets.php, /wp-admin/index.php, /wp-admin/themes.php, and a few more) ever 2.5-3 min, even if nothing on the pages was touched. While this issue doesn’t cause any problems if you only have one admin page open and close it after each use. But when you have multiple pages open and leave them open all day or over night WP will continue to make the POST to admin-ajax.php. After multiple hours (10+ when it is easiest to see) all of these continual POSTs will starts to negatively impact MYSQL. Database connection from admin-ajax.php will just sleep for multiple seconds even thought nothing is going on.

    For reference In WP 3.5 admin-ajax.php was only called automatically on the post.php page (I believe for autosave purposes). Also on 3.7.1 I switched to the default twenty thirteen theme and deactivated all the plugins and the auto POST things is still occurring.

    What is the point of admin-ajax.php being called on pages where no information was change and no ajax was initiated? Is there a way to turn this off? Is this a feature of WP and expected functionality?

    Thanks
    Greg

Viewing 15 replies - 1 through 15 (of 38 total)
  • It’s most likely the WordPress Heartbeat API introduced in WP 3.6.

    Using the WordPress Heartbeat API

    The Heartbeat API: Changing the Pulse

    I’ve not done this myself, so I’m not sure if this is the complete solution, but you should be able to add this to functions.php to stop the API:

    remove_action( ‘admin_init’, ‘wp_auth_check_load’ );

    Moderator Pippin Williamson

    @mordauk

    I’ve managed to bring down server servers by using the Heartbeat API on the frontend. You need to be very, very careful with it.

    optimized-marketing

    @optimized-marketingcom

    Thanks, Someone else mentioned the Heartbeat API as a possible culprit. I will remove the action and see if that prevents it from being called. Will let you know how it goes.

    Greg

    optimized-marketing

    @optimized-marketingcom

    I added remove_action( ‘admin_init’, ‘wp_auth_check_load’ ); to my functions.php file yet WP is still loads admin-ajax.php same as it did before. ever 2.5-3 min it does a POST

    It does seem to be related to heartbeat though. here is the postdata: POSTDATA=data%5Bwp-auth-check%5D=true&interval=15&_nonce=628a115b24&action=heartbeat&screen_id=theme-editor&has_focus=true

    Since that didnt work any other ideas?

    Yes, given the time interval and given the log snippet you posted, I’d guess with confidence that it’s the heartbeat api. (that’s the normal time interval, though I do think it slows down after a period of inactivity) It’s not something I’ve actually tried to do, and I wasn’t 100% sure if what I gave you would work.

    Is there a reason you need to have multiple admin pages open constantly? The obvious and easiest solution is not to do that.

    Maybe Pippin or someone else knows, but I’m not sure how to disable it (or if you really should), but I may look into it when I have more time over the weeekend…

    optimized-marketing

    @optimized-marketingcom

    That is just how I work on WP sites, I may also be working on multiple WP sites at one time,which are hosted on the same server. I like to have multiple tabs open for each area so I don’t have to keep reloading pages or re-navigate to them for the needed information. Efficiency Reasons.

    You are right just have one or two open is the easiest and most obvious solution along with closing down the admin section whenever not in use. That is a Process/Systems Solution I am going to implement. I don’t see that as a fix to the issue, because if someone accidentally leave some open over night or during the day, I don’t want all my sites to go down again.

    My ultimate goal is to talk to a WP developers to see if this is a known or expected experience. If not maybe add something to stop the heartbeat after a certain sleep setting or combine all the heartbeats into POST or something.

    Thanks for the help, hopefully someone else has some other ideas.

    Good luck – sounds like an edge case, but a perfectly valid one. AFAIK, the heartbeat only stops when you close your browser, but does slow down after (I think) five minutes of inactivity. But I’m not aware of any built-in way to turn it off. Also, as I think Pippin was alluding to, plugin developers do have the ability to decrease the ping time through a hook, down to once every 10-15 seconds I believe.

    Moderator Pippin Williamson

    @mordauk

    Yes, that’s correct. The pulse rate can be changed from a plugin.

    optimized-marketing

    @optimized-marketingcom

    I talked to someone working on heartbeat performance. They told me they have a few plans for a future WP update. They did give me away to turn it off. They suggested keep it on for the post page and new post page, so autosave continues to work.

    Add the following to functions.php to turn off heartbeat:

    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');
    }

    [Content removed by poster]

    So did this code work for anyone?? I’m leery of adding this code unless can definitively say it works 🙂 Thanks

    Yes, It works!

    I was experiencing the same problem… Too slow when browsing the site and even more slow when using the admin page.

    I do not have use for the auto save option, so disabling it is not a problem at all.

    I just used the above code in both my sites and the problem is resolved!

    http://www.copamundial2014brasil.com.br and http://www.precodehotel.com.br.

    Is the code supposed to be added to the wordpress’ core functions.php or the theme’s functions.php. which is which??

    esmi

    @esmi

    Forum Moderator

    Your theme’s functions.php file. You should never touch WordPress core files.

    Thanks, esmi for the quick response

Viewing 15 replies - 1 through 15 (of 38 total)
  • The topic ‘Admin-ajax.php being Called from Admin Pages Causing DB Connection Issues’ is closed to new replies.
Skip to toolbar