PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.0.0
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.0.0
1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 All 29 releases
xspeed / includes / class-server.php

class-server.php in xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN 1.0.0, at includes/class-server.php

72 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server / SAPI detection.
4 *
5 * Used by Gzip and the UI to decide which optimizations are server-applied
6 * (Apache / LiteSpeed via .htaccess) vs. require manual config (nginx).
7 *
8 * @package XSpeed
9 */
10
11 namespace XSpeed;
12
13 defined( 'ABSPATH' ) || exit;
14
15 class Server {
16
17 const APACHE = 'apache';
18 const LITESPEED = 'litespeed';
19 const NGINX = 'nginx';
20 const IIS = 'iis';
21 const UNKNOWN = 'unknown';
22
23 public static function type() {
24 global $is_apache, $is_nginx, $is_IIS, $is_iis7;
25
26 $signature = self::server_signature();
27
28 if ( false !== stripos( $signature, 'litespeed' ) ) {
29 return self::LITESPEED;
30 }
31 if ( ! empty( $is_apache ) || function_exists( 'apache_get_modules' ) || false !== stripos( $signature, 'apache' ) ) {
32 return self::APACHE;
33 }
34 if ( ! empty( $is_nginx ) || false !== stripos( $signature, 'nginx' ) ) {
35 return self::NGINX;
36 }
37 if ( ! empty( $is_IIS ) || ! empty( $is_iis7 ) || false !== stripos( $signature, 'microsoft-iis' ) ) {
38 return self::IIS;
39 }
40
41 // Fallback: presence of .htaccess implies an Apache-compatible host.
42 if ( file_exists( ABSPATH . '.htaccess' ) ) {
43 return self::APACHE;
44 }
45
46 return self::UNKNOWN;
47 }
48
49 /**
50 * Whether the server respects .htaccess / web.config-style file-based config.
51 */
52 public static function supports_htaccess() {
53 $t = self::type();
54 return self::APACHE === $t || self::LITESPEED === $t;
55 }
56
57 /**
58 * GZIP support category for the UI:
59 * 'auto' — toggling writes server config (Apache / LiteSpeed)
60 * 'manual' — must be configured outside the plugin (nginx, IIS, unknown)
61 */
62 public static function gzip_mode() {
63 return self::supports_htaccess() ? 'auto' : 'manual';
64 }
65
66 private static function server_signature() {
67 return isset( $_SERVER['SERVER_SOFTWARE'] )
68 ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) )
69 : '';
70 }
71 }
72