Support » Developing with WordPress » Extremely long TTFB for admin-ajax.php

  • Hello. I am currently developing a custom theme that makes use of AJAX functionality. I am basically displaying post content data & latest post’s dynamiacally with AJAX.

    Could someone suggest me any good ways of debugging or what could be the cause of a very huge Waiting (TTFB) for admin-ajax.php file. The TTFB is around 10 seconds.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If the content inserted contains many image or other external references, fetching all of those can take some time, especially large retina images. I realize this occurs after TTFB. It’s worth looking into anyway. Check you browser’s network tool to see what else is happening besides the Ajax call. The bottleneck may not be just Ajax per se, but the aftermath.

    I’m assuming the TTFB for normal page requests are within reason, ruling out general server and host issues. If your Ajax handler causes multiple and/or extensive DB queries, especially when large DBs are involved, that will suck up a lot of time. Ajax handlers are difficult to debug. Your best resource is your server error log and the error_log() function. Salt into your Ajax handler several error_log calls that include the value returned by microtime(). Place the calls after functions that result in DB queries and other suspected bottlenecks. Generally, the numbers should be very close to each other. Any significant gaps indicate a bottleneck that should be addressed.

    Making DB queries more efficient depend on what the hangup is. If it’s simply a very large DB, there are ways to optimize it, but again, the solution depends on what the hangup is. DB optimization is part art and a bit of black magic combined with knowledge, experience, and skill. There is not a clear path to success.

    In other words, I’ve no idea how to improve someone else’s large DB. You could try the table maintenance operations in phpMyAdmin, but I’d be surprised if they made a big difference. Still, it’s one of the first things to try.

    AJAX is a javascript method, which means it is executed after the browser receives the first byte of data from the server (TTFB). So use of admin-ajax.php has no effect on TTFB. I suspect you are talking about the time to completely load the page.

    AJAX via admin-ajax.php is usually a bad idea on the frontend. A full copy of WordPress, including plugins, is loaded every time you make a call to admin-ajax.php. That can cause delays in loading a page, especially if you’re making multiple AJAX calls.

    There are many ways to speed up what you are doing. One is to stop using AJAX on the frontend and do everything within your theme. That can create issues with TTFB, in which case you can cache the results of your expensive queries and update them at some set interval (perhaps every 15 minutes).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Extremely long TTFB for admin-ajax.php’ is closed to new replies.