| @@ -75,8 +75,52 @@ | ||
| 75 | 75 | * embedded when nginx is detected. Skipped entirely when cache is |
| 76 | 76 | * disabled — no point telling the user to install a rewrite they |
| 77 | 77 | * haven't opted into. |
| 78 | 78 | */ |
| 79 | + /** | |
| 80 | + * Decide what the nginx static rewrite is actually doing. | |
| 81 | + * | |
| 82 | + * Extracted so the ordering is testable without a WordPress bootstrap, | |
| 83 | + * and so Site Health and the dashboard Health panel cannot drift apart | |
| 84 | + * again — the whole point of #480. | |
| 85 | + * | |
| 86 | + * Returns one of: 'active', 'mobile_separate', 'skipped_nonce', | |
| 87 | + * 'unverified', 'required'. | |
| 88 | + * | |
| 89 | + * @param array<string, mixed> $probe probe_static_rewrite() result. | |
| 90 | + * @param string $block_reason A known refusal, or ''. | |
| 91 | + */ | |
| 92 | + public static function nginx_rewrite_verdict( array $probe, string $block_reason ): string { | |
| 93 | + $is_active = (bool) ( $probe['active'] ?? false ); | |
| 94 | + $inconclusive = (bool) ( $probe['inconclusive'] ?? false ); | |
| 95 | + | |
| 96 | + // A known refusal OUTRANKS the probe. probe_static_rewrite() writes | |
| 97 | + // its own file under the static-cache dir and fetches that, which | |
| 98 | + // succeeds whenever the server can serve a static file at all — even | |
| 99 | + // when no real page is on the static path. It also outranks | |
| 100 | + // "inconclusive", so a blocked rewrite whose probe merely failed to | |
| 101 | + // complete is reported as the refusal it is. (FBS-83145) | |
| 102 | + if ( '' !== $block_reason ) { | |
| 103 | + if ( 'mobile_separate' === $block_reason ) { | |
| 104 | + return 'mobile_separate'; | |
| 105 | + } | |
| 106 | + if ( 'skipped_nonce' === $block_reason ) { | |
| 107 | + return 'skipped_nonce'; | |
| 108 | + } | |
| 109 | + return 'required'; | |
| 110 | + } | |
| 111 | + | |
| 112 | + if ( $is_active ) { | |
| 113 | + return 'active'; | |
| 114 | + } | |
| 115 | + | |
| 116 | + // The probe never reached a verdict (blocked loopback, self-signed | |
| 117 | + // cert, timeout, a CDN/WAF answering instead of the origin). That is | |
| 118 | + // not evidence the config is wrong, and must not produce a | |
| 119 | + // "paste this snippet" banner. (FBS-84012, #480) | |
| 120 | + return $inconclusive ? 'unverified' : 'required'; | |
| 121 | + } | |
| 122 | + | |
| 79 | 123 | public function site_status_static_rewrite(): array { |
| 80 | 124 | $result = array( |
| 81 | 125 | 'label' => __( 'xSpeed static-rewrite cache is active', 'xspeed' ), |
| 82 | 126 | 'status' => 'good', |
| @@ -103,9 +147,16 @@ | ||
| 103 | 147 | // "toggle Enable Cache off and on" cannot reinstall anything — |
| 104 | 148 | // the same condition suppresses the write and auto_heal() strips |
| 105 | 149 | // the block again on the next admin load. Explain the real cause. |
| 106 | 150 | $block_reason = \XSpeed\Cache::static_rewrite_block_reason(); |
| 107 | - if ( 'no_mod_headers' === $block_reason ) { | |
| 151 | + if ( 'litespeed_dropin' === $block_reason ) { | |
| 152 | + // The intended LiteSpeed default (#509) — 'good', not a nag: | |
| 153 | + // hits are visible and counted, and the faster path is a | |
| 154 | + // deliberate opt-in, not a missing config. | |
| 155 | + $result['label'] = __( 'xSpeed is serving cache hits through PHP (LiteSpeed)', 'xspeed' ); | |
| 156 | + $result['status'] = 'good'; | |
| 157 | + $result['description'] = '<p>' . esc_html__( 'Caching is working — hits are served by the xSpeed drop-in and tagged X-XSpeed-Cache: HIT (php), so every hit is visible and counted. LiteSpeed\'s .htaccess engine cannot tag or log statically served files, so this is the default. To serve hits straight from the web server with no PHP (at the cost of that tagging and counting), turn on LiteSpeed Static Fast Path in xSpeed\'s Cache settings.', 'xspeed' ) . '</p>'; | |
| 158 | + } elseif ( 'no_mod_headers' === $block_reason ) { | |
| 108 | 159 | $result['label'] = __( 'xSpeed is serving cache hits through PHP', 'xspeed' ); |
| 109 | 160 | $result['status'] = 'recommended'; |
| 110 | 161 | $result['description'] = '<p>' . esc_html__( 'Caching is working — hits are served by the xSpeed drop-in and tagged X-XSpeed-Cache: HIT (php). The faster .htaccess fast path is off because Apache\'s mod_headers module is not loaded, without which a static hit could not be tagged or counted. Enable mod_headers (a2enmod headers on Debian/Ubuntu, then restart Apache) to shave roughly 20-30ms off each cache hit.', 'xspeed' ) . '</p>'; |
| 111 | 162 | } elseif ( 'mobile_separate' === $block_reason ) { |
| @@ -111,9 +162,11 @@ | ||
| 111 | 162 | } elseif ( 'mobile_separate' === $block_reason ) { |
| 112 | 163 | $result['label'] = __( 'xSpeed static rewrite is off (Separate Mobile Cache)', 'xspeed' ); |
| 113 | 164 | $result['status'] = 'recommended'; |
| 114 | 165 | $result['description'] = '<p>' . esc_html__( 'Separate Mobile Cache is on, so cache hits are served by the PHP drop-in to keep per-device HTML correct. Turn Separate Mobile Cache off if your site serves the same HTML to every device to regain the faster static path.', 'xspeed' ) . '</p>'; |
| 115 | - } elseif ( \XSpeed\Server::APACHE === $server_type && ! \XSpeed\Cache::rewrite_installed() ) { | |
| 166 | + } elseif ( '' === $block_reason && ! \XSpeed\Cache::rewrite_installed() ) { | |
| 167 | + // Apache, or LiteSpeed with the Static Fast Path opt-in on | |
| 168 | + // (#509) — either way the block SHOULD be there and is not. | |
| 116 | 169 | $result['label'] = __( 'xSpeed .htaccess rewrite block is missing', 'xspeed' ); |
| 117 | 170 | $result['status'] = 'recommended'; |
| 118 | 171 | $result['description'] = '<p>' . esc_html__( 'Without the static-rewrite block, cache hits go through the PHP drop-in (~85ms TTFB) instead of the web server (~5-15ms). Toggle Enable Cache off and on in xSpeed to reinstall the block.', 'xspeed' ) . '</p>'; |
| 119 | 172 | } |
| @@ -120,8 +173,62 @@ | ||
| 120 | 173 | return $result; |
| 121 | 174 | } |
| 122 | 175 | |
| 123 | 176 | if ( \XSpeed\Server::NGINX === $server_type ) { |
| 177 | + // Ask the same question the dashboard Health panel asks, the same | |
| 178 | + // way. This test used to return "config required" unconditionally, | |
| 179 | + // so every correctly-configured nginx site — every xCloud site, | |
| 180 | + // where the panel installs the block for you — was told to paste a | |
| 181 | + // snippet it already had, and re-running the check never cleared | |
| 182 | + // it. Worse, the dashboard said the opposite at the same moment. | |
| 183 | + // Reuse probe_static_rewrite() + the refusal reasons so the two | |
| 184 | + // surfaces cannot disagree. (#480) | |
| 185 | + $probe = \XSpeed\Cache::probe_static_rewrite( true ); | |
| 186 | + $probe_reason = (string) ( $probe['reason'] ?? '' ); | |
| 187 | + | |
| 188 | + $block_reason = \XSpeed\Cache::static_rewrite_block_reason(); | |
| 189 | + $skip = \XSpeed\Cache::last_static_skip(); | |
| 190 | + if ( '' === $block_reason && ! empty( $skip['reason'] ) ) { | |
| 191 | + $block_reason = 'skipped_' . (string) $skip['reason']; | |
| 192 | + } | |
| 193 | + | |
| 194 | + switch ( self::nginx_rewrite_verdict( $probe, $block_reason ) ) { | |
| 195 | + case 'active': | |
| 196 | + $result['label'] = __( 'xSpeed nginx static rewrite is active', 'xspeed' ); | |
| 197 | + $result['status'] = 'good'; | |
| 198 | + $result['description'] = '<p>' . esc_html__( 'nginx is serving cache hits directly — PHP is bypassed (~5-15ms TTFB). No action needed.', 'xspeed' ) . '</p>'; | |
| 199 | + return $result; | |
| 200 | + | |
| 201 | + case 'mobile_separate': | |
| 202 | + $result['label'] = __( 'xSpeed static rewrite is off (Separate Mobile Cache)', 'xspeed' ); | |
| 203 | + $result['status'] = 'recommended'; | |
| 204 | + $result['description'] = '<p>' . esc_html__( 'Separate Mobile Cache is on, so cache hits are served by the PHP drop-in to keep per-device HTML correct. Turn Separate Mobile Cache off if your site serves the same HTML to every device to regain the faster static path.', 'xspeed' ) . '</p>'; | |
| 205 | + return $result; | |
| 206 | + | |
| 207 | + case 'skipped_nonce': | |
| 208 | + $result['label'] = __( 'xSpeed is serving cache hits through PHP (pages contain nonces)', 'xspeed' ); | |
| 209 | + $result['status'] = 'recommended'; | |
| 210 | + $result['description'] = '<p>' . esc_html__( 'Your nginx config is correct, but pages are not reaching the static cache, so hits are served by PHP. They contain nonces, and a static file is served with no PHP — nothing could ever refresh them, so every anonymous form on the page would break once they expire. Keeping these pages on PHP is deliberate.', 'xspeed' ) . '</p>'; | |
| 211 | + return $result; | |
| 212 | + | |
| 213 | + case 'unverified': | |
| 214 | + // The probe never reached a verdict (blocked loopback, | |
| 215 | + // self-signed cert, timeout, a CDN/WAF answering instead of | |
| 216 | + // the origin). Not evidence the config is wrong, so don't | |
| 217 | + // say "required" and don't dump a snippet the user has | |
| 218 | + // probably already pasted. (FBS-84012, and why #480 was filed.) | |
| 219 | + $result['label'] = __( 'xSpeed could not verify the nginx static rewrite', 'xspeed' ); | |
| 220 | + $result['status'] = 'recommended'; | |
| 221 | + $result['description'] = '<p>' . esc_html( | |
| 222 | + sprintf( | |
| 223 | + /* translators: %s: the reason the probe could not complete. */ | |
| 224 | + __( 'The check itself did not complete, so this is not evidence that your config is wrong — if you have already pasted the snippet it may well be working. Reason: %s', 'xspeed' ), | |
| 225 | + $probe_reason | |
| 226 | + ) | |
| 227 | + ) . '</p>'; | |
| 228 | + return $result; | |
| 229 | + } | |
| 230 | + | |
| 124 | 231 | $snippet = \XSpeed\Cache::nginx_snippet(); |
| 125 | 232 | $result['label'] = __( 'xSpeed nginx server config required', 'xspeed' ); |
| 126 | 233 | $result['status'] = 'recommended'; |
| 127 | 234 | $result['description'] = '<p>' . esc_html__( 'xSpeed can\'t write nginx config from PHP. Paste this snippet into your site\'s server { } block, then reload nginx so cache hits serve without booting PHP:', 'xspeed' ) . '</p>' |