12, 'redirection' => 3, 'sslverify' => false, 'cookies' => array(), 'headers' => array( 'Accept-Encoding' => 'gzip', 'User-Agent' => 'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36 AIO-Speed-Audit/' . ( defined( 'AIO_VERSION' ) ? AIO_VERSION : '3.1.0' ), ), ); $t0 = microtime( true ); $response = wp_remote_get( $home_url, $request_args ); $ttfb_ms = (int) round( ( microtime( true ) - $t0 ) * 1000 ); $loopback_ok = ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200; $loopback_err = is_wp_error( $response ) ? $response->get_error_message() : ''; $html = $loopback_ok ? (string) wp_remote_retrieve_body( $response ) : ''; $headers = $loopback_ok ? wp_remote_retrieve_headers( $response ) : array(); $aio_cache_hdr = $loopback_ok ? strtoupper( (string) wp_remote_retrieve_header( $response, 'x-aio-cache' ) ) : ''; // If Page Cache is enabled and first request just warmed the cache (MISS), measure warm HIT TTFB! if ( $loopback_ok && ! empty( $options['optEnablePageCache'] ) && $aio_cache_hdr === 'MISS' ) { $t1 = microtime( true ); $res2 = wp_remote_get( $home_url, array_merge( $request_args, array( 'timeout' => 5 ) ) ); $warm_ms = (int) round( ( microtime( true ) - $t1 ) * 1000 ); if ( ! is_wp_error( $res2 ) && wp_remote_retrieve_response_code( $res2 ) === 200 ) { $ttfb_ms = $warm_ms; $aio_cache_hdr = strtoupper( (string) wp_remote_retrieve_header( $res2, 'x-aio-cache' ) ); } } // Detect active caching layer $third_party_cache = ''; if ( defined( 'LSCACHE_V' ) || class_exists( 'LiteSpeed_Cache' ) || ( $loopback_ok && wp_remote_retrieve_header( $response, 'x-litespeed-cache' ) ) ) { $third_party_cache = 'LiteSpeed Cache'; } elseif ( defined( 'WP_ROCKET_VERSION' ) ) { $third_party_cache = 'WP Rocket'; } elseif ( $loopback_ok && strtolower( (string) wp_remote_retrieve_header( $response, 'cf-cache-status' ) ) === 'hit' ) { $third_party_cache = 'Cloudflare Edge'; } $cache_status = 'OFF'; if ( ! empty( $aio_cache_hdr ) && strpos( $aio_cache_hdr, 'HIT' ) === 0 ) { $cache_status = $aio_cache_hdr; } elseif ( ! empty( $third_party_cache ) ) { $cache_status = $third_party_cache; } elseif ( $perf_active && ! empty( $options['optEnablePageCache'] ) ) { $cache_status = 'WARMING'; } // Analyze HTML structure if loopback succeeded $html_kb = $loopback_ok ? round( strlen( $html ) / 1024, 1 ) : 0; $dom_nodes = 0; $blocking_css = 0; $blocking_js = 0; $missing_dims = 0; $lcp_lazy_issue = false; $lcp_missing_priority = false; $youtube_iframes = 0; $google_fonts_noswap = false; $google_fonts_remote = false; $hardcoded_raster_imgs = 0; $has_dashicons_guest = false; $has_jq_migrate_guest = false; $has_wp_emoji_guest = false; $detected_trackers = array(); $suggested_preconnect = array(); if ( $loopback_ok && $html !== '' ) { // Strip script/style/noscript/template before counting DOM elements & inspecting /