$xspeed_cookie_value ) { unset( $xspeed_cookie_value ); $xspeed_cookie_name = (string) $xspeed_cookie_name; if ( 0 === strpos( $xspeed_cookie_name, 'wordpress_logged_in' ) || 0 === strpos( $xspeed_cookie_name, 'comment_author_' ) || 0 === strpos( $xspeed_cookie_name, 'wp-postpass_' ) ) { return; } } } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Drop-in runs before wp_unslash()/sanitize_text_field() are loaded. Value is filtered through a strict allowlist regex below (letters, digits, dot, hyphen, colon) and only used as md5() input for the cache key. $xspeed_host = isset( $_SERVER['HTTP_HOST'] ) ? (string) $_SERVER['HTTP_HOST'] : 'default'; $xspeed_host = str_replace( "\0", '', $xspeed_host ); // Restrict host to a safe charset (letters, digits, dot, hyphen, colon for port). $xspeed_host = preg_replace( '/[^a-zA-Z0-9.\-:]/', '', $xspeed_host ); $xspeed_path_only = strtok( $xspeed_request_uri, '?' ); $xspeed_cache_key = md5( $xspeed_host . $xspeed_path_only ); $xspeed_cache_file = WP_CONTENT_DIR . '/cache/xspeed/' . $xspeed_cache_key . '.html'; if ( file_exists( $xspeed_cache_file ) ) { // 24h TTL in seconds. HOUR_IN_SECONDS is a WordPress constant defined // after this drop-in loads, so use a literal here. $xspeed_age = time() - filemtime( $xspeed_cache_file ); if ( $xspeed_age < 86400 ) { // PHP-served cache hit (the ~85ms fallback path). The nginx static // rewrite sends "HIT (nginx)" for the fast 5-15ms path; same header, // distinct value so you can tell which layer served the page. header( 'X-XSpeed-Cache: HIT (php)' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Drop-in runs before WP_Filesystem is available; readfile is optimal for streaming a static cache file to the visitor. readfile( $xspeed_cache_file ); exit; } }