class-litespeed-integration.php

LiteSpeed Integration class for the PerformanceOptimise plugin.

Source includes/Integrations/class-litespeed-integration.php12 min readPart of Performance Optimisation

includes/Integrations/class-litespeed-integration.php

LiteSpeed Integration class for the PerformanceOptimise plugin.

Namespace: PerformanceOptimise\\Inc · Lines: 2797

Class LiteSpeed_Integration

Class LiteSpeed_Integration

Source: includes/Integrations/class-litespeed-integration.php, line 29

final class LiteSpeed_Integration

Tags: @since 2.0.0

Constants

ConstantVisibilityValueLine
MODE_AUTOpublic\'auto\'37
MODE_WPPOpublic\'wppo\'45
MODE_LITESPEEDpublic\'litespeed\'53
MODE_STANDALONEpublic\'standalone\'61
ALLOWED_MODESprivatearray( self::MODE_AUTO, self::MODE_WPPO, self::MODE_LITESPEED, self::MODE_STANDALONE, )69
PURGE_LOCKprivate\'wppo_litespeed_purge_lock\'85
PURGE_LOCK_TTLprivate6093
DB_QUEUEpublic\'wppo_litespeed_purge_queue\'620
TAG_QUEUEprivate\'wppo_lscache_tag_queue\'628
TAG_QUEUE_MAXprivate100636
DB_QUEUE_MAXprivate200644
DB_QUEUE_TTLprivateHOUR_IN_SECONDS652

Properties

PropertyVisibilityTypeDefaultLine
$cached_effective_modeprivate static?stringnull103
$exclude_urls_memoprivate static?arraynull111
$cached_modeprivate static?stringnull119
$cached_is_litespeedprivate static?boolnull127
$cached_is_lscache_activeprivate static?boolnull135
$cached_ttlprivate static?intnull145
$cached_is_cacheableprivate static?boolnull155
$cached_should_varyprivate static?boolnull165
$cached_nextgenprivate static?boolnull173
$cached_brotliprivate static?boolnull181
$cached_can_cdnprivate static?boolnull189
$uri_post_memoprivate staticarrayarray()197
$purge_tags_memoprivate static?arraynull210
$hooks_registeredprivate staticboolfalse220
$queue_shutdown_hookedprivate staticboolfalse660
$tag_bufferprivate staticarrayarray()675
$tag_buffer_scopesprivate staticarrayarray()683

publicstatic is_litespeed()

public static function is_litespeed(): bool

Whether the current server is LiteSpeed / OpenLiteSpeed.

Return: bool — True if LiteSpeed or OpenLiteSpeed is detected.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 230

publicstatic is_lscache_active()

public static function is_lscache_active(): bool

Whether the LiteSpeed Cache plugin (LSCWP) is active.

Return: bool — True if LiteSpeed Cache plugin is active.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 264

publicstatic get_mode()

public static function get_mode(): string

Get the configured LiteSpeed integration mode.

Return: string — One of self::MODE_* constants.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 329

publicstatic effective_mode()

public static function effective_mode(): string

Get the effective (resolved) LiteSpeed integration mode.

Return: string — One of self::MODE_* concrete modes (never \’auto\’).

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 376

publicstatic is_wppo_cache_owner()

public static function is_wppo_cache_owner(): bool

Whether WPPO owns the page cache (is the cache owner).

Return: bool — True if WPPO is the cache owner.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 441

publicstatic should_disable_wppo_optimizer()

public static function should_disable_wppo_optimizer(): bool

Whether WPPO should disable its optimizer (minify/combine/defer/delay).

Return: bool — True if WPPO optimizer should be disabled.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 465

publicstatic is_purge_sync_enabled()

public static function is_purge_sync_enabled(): bool

Whether purge sync is enabled (WPPO ↔ LSCache).

Return: bool — True if purges should be synced.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 500

publicstatic get_purge_lock_key()

public static function get_purge_lock_key(): string

Get the blog-prefixed purge-lock transient key.

Return: string — Transient key.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 526

publicstatic has_purge_lock()

public static function has_purge_lock(): bool

Whether a purge-loop lock is currently active.

Return: bool — True if lock present.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 536

publicstatic set_purge_lock()

public static function set_purge_lock(): void

Set the purge-loop lock for PURGE_LOCK_TTL seconds.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 546

publicstatic sync_purge_all_to_litespeed()

public static function sync_purge_all_to_litespeed(): void

Sync a WPPO \”purge all\” to LSCache.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 560

publicstatic sync_purge_url_to_litespeed()

public static function sync_purge_url_to_litespeed(string $url_path): void

Sync a WPPO single-page purge to LSCache via URL.

ParameterTypeDefaultDescription
$url_pathstring—URL path (e.g. \”/about/\”).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 578

publicstatic sync_purge_post_to_litespeed()

public static function sync_purge_post_to_litespeed(int $post_id): void

Sync a WPPO post invalidation to LSCache via post ID.

ParameterTypeDefaultDescription
$post_idint—Post ID.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 600

publicstatic queue_purge_tags()

public static function queue_purge_tags(array $tags, string=\'public\' $scope): void

Queue LiteSpeed purge tags (P3).

ParameterTypeDefaultDescription
$tagsarray—Tag strings (e.g. Po.123, T.5, F).
$scopestring=\'public\'—Scope: public|private|stale.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 696

privatestatic maybe_hook_shutdown()

private static function maybe_hook_shutdown(): void

Ensure shutdown flush is hooked once.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 759

publicstatic flush_tag_queue()

public static function flush_tag_queue(): void

Flush queued tags via X-LiteSpeed-Purge and litespeed_purge action.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 775

privatestatic read_db_queue()

private static function read_db_queue(string $db_key): array

Read the DB_QUEUE fallback option.

ParameterTypeDefaultDescription
$db_keystring—Option key (blog-prefixed).

Return: string[] — Valid queued tags.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 861

privatestatic write_db_queue()

private static function write_db_queue(string $db_key, array $tags): void

Persist purge tags to the DB_QUEUE fallback option.

ParameterTypeDefaultDescription
$db_keystring—Option key (blog-prefixed).
$tagsarray—Tags to persist.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 902

publicstatic get_db_queue_key()

public static function get_db_queue_key(): string

Get DB queue option key (blog-prefixed).

Return: string.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 936

publicstatic init()

public static function init(): void

Initialise LiteSpeed integration hooks.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 950

publicstatic invalidate_uri_post_map()

public static function invalidate_uri_post_map(): void

Invalidate the URI-to-post-ID persistent map.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 983

publicstatic handle_litespeed_purged_all()

public static function handle_litespeed_purged_all(): void

Handle LSCache \”purged all\” → clear WPPO file cache.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1001

publicstatic handle_litespeed_purged_post()

public static function handle_litespeed_purged_post($post_id): void

Handle LSCache \”purged post\” → invalidate WPPO static HTML for post.

ParameterTypeDefaultDescription
$post_idint—Post ID purged by LSCache.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1021

publicstatic handle_litespeed_purge_finalize()

public static function handle_litespeed_purge_finalize(): void

Handle LSCache purge finalize (catch-all) → clear WPPO cache.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1048

privatestatic cached_uri_to_post_id()

private static function cached_uri_to_post_id(string $uri): int

Resolve a URI to a post ID using per-request + persistent caches.

ParameterTypeDefaultDescription
$uristring—Request URI.

Return: int — Post ID (0 when unresolvable).

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1072

privatestatic store_uri_to_post_id()

private static function store_uri_to_post_id(string $uri, int $post_id): void

Store a URI-to-post-ID resolution in per-request + persistent caches.

ParameterTypeDefaultDescription
$uristring—Request URI.
$post_idint—Resolved post ID (0 for negative).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1100

publicstatic get_litespeed_ttl()

public static function get_litespeed_ttl(?string=null $uri, =null $post_id): int

Get LiteSpeed cache TTL in seconds mapped from cacheLife hours with per-context overrides.

ParameterTypeDefaultDescription
$uri?string=null—Optional URI for per-page TTL.
$post_id=null—Optional post ID.

Return: int — TTL seconds (>=0, 0 = no-cache).

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1141

publicstatic is_request_cacheable()

public static function is_request_cacheable(): bool

Whether current request is cacheable for LiteSpeed layer.

Return: bool — True if cacheable.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1369

publicstatic should_vary_by_role()

public static function should_vary_by_role(): bool

Whether vary-by-role should be added for LiteSpeed.

Return: bool — True if vary bridge should be active.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1488

publicstatic get_vary_groups()

public static function get_vary_groups(): array

Get active Vary groups (P2).

Return: array{role:bool,guest:bool,mobile:bool,webp:bool,commenter:bool,postpass:bool}.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1524

publicstatic is_commenter_request()

public static function is_commenter_request(): bool

Whether current request has a commenter cookie (LS-320).

Return: bool — True if commenter cookie present.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1560

publicstatic is_postpass_request()

public static function is_postpass_request(): bool

Whether current request has a post password cookie (LS-320).

Return: bool — True if postpass cookie present.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1587

publicstatic is_private_request()

public static function is_private_request(): bool

Whether current request should be treated as private/nocache (LS-320).

Return: bool — True if request should be private/nocache.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1624

public static function seed_lscache_vary_cookie(): void

Seed _lscache_vary cookie for LSWS vary handshake (LS-320).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1644

privatestatic get_vary_role_value()

private static function get_vary_role_value(): string

Get the vary role value — group 99 for admin (LSCWP parity).

Return: string — Role value (99 for admin, role hash otherwise).

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1726

privatestatic client_supports_webp()

private static function client_supports_webp(): bool

Whether the current client supports WebP images.

Return: bool — True if Accept header contains image/webp or image/avif.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1765

public static function clear_lscache_vary_cookie(): void

Clear _lscache_vary cookie on logout.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1776

privatestatic strip_crlf()

private static function strip_crlf(string $value): string

Strip CR/LF (and NUL) bytes from a value before it is passed to header().

ParameterTypeDefaultDescription
$valuestring—Header value to clean.

Return: string — Value without header-breaking control characters.

Tags: @deprecated NEXT Use Header_Emitter::strip_crlf() directly. · @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1813

publicstatic build_vary_header()

public static function build_vary_header(): string

Build fallback vary header value from active groups (P2).

Return: string — Vary header value.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1823

publicstatic handle_send_headers()

public static function handle_send_headers(): void

Handle send_headers — LS-native header emission (LS-301/302/304).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1867

privatestatic send_litespeed_ttl()

private static function send_litespeed_ttl(int $ttl): void

Send LiteSpeed TTL header (public,max-age=N).

ParameterTypeDefaultDescription
$ttlint—TTL seconds.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 1996

privatestatic send_litespeed_nocache()

private static function send_litespeed_nocache(string $reason): void

Send LiteSpeed no-cache header for non-cacheable routes.

ParameterTypeDefaultDescription
$reasonstring—Reason for nocache (for LSCWP logging).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2032

publicstatic get_litespeed_tags_for_purge()

public static function get_litespeed_tags_for_purge(): array

Build full LiteSpeed tag fan-out for current request.

Return: string[].

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2076

publicstatic invalidate_purge_tags_memo()

public static function invalidate_purge_tags_memo(): void

Invalidate the purge-tags memo.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2095

publicstatic resolve_ttl_override_hours()

public static function resolve_ttl_override_hours($post_id, $post_type, bool $is_singular_ctx, $overrides): ?int

Resolve per-post-type TTL override hours (pure).

ParameterTypeDefaultDescription
$post_idint|null—Resolved post ID or null.
$post_typestring|null—Resolved post type or null.
$is_singular_ctxbool—Whether the current context is singular.
$overridesmixed—Stored ttlOverrides value.

Return: int|null — Override hours or null.

Tags: @since 2.2.0

Source: includes/Integrations/class-litespeed-integration.php, line 2113

publicstatic map_hours_to_seconds()

public static function map_hours_to_seconds(int $hours): int

Map cacheLife hours to TTL seconds (pure).

ParameterTypeDefaultDescription
$hoursint—CacheLife hours.

Return: int — TTL seconds.

Tags: @since 2.2.0

Source: includes/Integrations/class-litespeed-integration.php, line 2133

publicstatic build_litespeed_tags()

public static function build_litespeed_tags(array $facts): array

Build the LiteSpeed tag fan-out from resolved facts (pure).

ParameterTypeDefaultDescription
$factsarray—Resolved facts: is_front, is_home, is_paged, is_singular, post_id, post_type, term_ids, author, date_ymd, blog_id, is_feed, is_rest, is_404.

Return: string[] — Tag list (deduplicated, WPPO + MIN included).

Tags: @since 2.2.0

Source: includes/Integrations/class-litespeed-integration.php, line 2151

privatestatic compute_litespeed_tags_for_purge()

private static function compute_litespeed_tags_for_purge(): array

Compute the full LiteSpeed tag fan-out for the current request.

Return: string[].

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2207

privatestatic send_litespeed_tags()

private static function send_litespeed_tags(): void

Send LiteSpeed tag headers (WPPO + full fan-out).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2373

publicstatic filter_litespeed_vary()

public static function filter_litespeed_vary($vary)

Filter litespeed_vary — append wppo_role_hash when vary bridge active.

ParameterTypeDefaultDescription
$varymixed—Vary value from LSCWP (array|string).

Return: mixed — Modified vary value.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2434

publicstatic is_nextgen_rewrite_enabled()

public static function is_nextgen_rewrite_enabled(): bool

Whether next-gen Vary:Accept rewrite is enabled (LS-401).

Return: bool — True if next-gen rewrite should be active.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2494

publicstatic is_nextgen_rewrite_enabled_for_nginx()

public static function is_nextgen_rewrite_enabled_for_nginx(): bool

Whether next-gen rewrite is enabled for Nginx/server_rules context (LS-402).

Return: bool — True if nginx next-gen map should be included.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2544

publicstatic is_nextgen_rewrite_enabled_for_apache()

public static function is_nextgen_rewrite_enabled_for_apache(): bool

Whether next-gen rewrite is enabled for Apache/.htaccess context.

Return: bool — True if the htaccess next-gen block should be included.

Tags: @since 2.2.0

Source: includes/Integrations/class-litespeed-integration.php, line 2577

publicstatic is_brotli_enabled()

public static function is_brotli_enabled(): bool

Whether Brotli .br generation is enabled (LS-403).

Return: bool — True if brotli generation should run.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2613

publicstatic can_apply_cdn()

public static function can_apply_cdn(): bool

Whether CDN rewriting is allowed by LiteSpeed guard (LS-404).

Return: bool — True if CDN rewriting may proceed.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2664

privatestatic maybe_strip_generic_cache_control()

private static function maybe_strip_generic_cache_control(): void

Strip generic Cache-Control when LS public header sent (LS-304).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2707

publicstatic reset_cache()

public static function reset_cache(): void

Reset all per-request caches (for testing).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2729

publicstatic get_info()

public static function get_info(): array

Get a structured LiteSpeed info array for REST/JS consumption.

Return: array{ — detected: bool, server_type: string, lscache_active: bool, mode: string, effective_mode: string, wppo_owns_cache: bool, optimizer_disabled: bool }.

Tags: @since 2.0.0

Source: includes/Integrations/class-litespeed-integration.php, line 2770

Hooks

Hooks referenced in includes/Integrations/class-litespeed-integration.php:

HookTypeLineNotes
wppo_litespeed_is_litespeedfilter250@param ×1
wppo_litespeed_is_lscache_activefilter315@param ×1
wppo_litespeed_modefilter348@param ×1
wppo_litespeed_effective_modefilter420@param ×2
wppo_litespeed_should_disable_optimizerfilter485@param ×2
wppo_litespeed_purge_syncfilter515@param ×1
wppo_litespeed_purge_tagsfilter735@param ×2
wppo_litespeed_purge_tag_stringfilter829@param ×2
wppo_cache_ttlfilter1330@param ×3
wppo_litespeed_ttlfilter1340@param ×3
wppo_litespeed_is_cacheablefilter1382@param ×1
wppo_litespeed_is_cacheablefilter1460@param ×1
wppo_litespeed_vary_enabledfilter1507@param ×1
wppo_litespeed_vary_groupsfilter1541@param ×1
wppo_litespeed_lscache_vary_valuefilter1687@param ×2
wppo_litespeed_vary_headerfilter1849@param ×2
wppo_litespeed_vary_fallbackfilter1972@param ×1
wppo_litespeed_ttlfilter1997@param ×1
wppo_litespeed_cache_control_headerfilter2011@param ×2
wppo_litespeed_nocache_reasonfilter2039@param ×1
wppo_litespeed_nocache_headerfilter2060@param ×2
wppo_litespeed_tag_post_idfilter2269—
wppo_litespeed_tagfilter2383@param ×1
wppo_litespeed_tag_post_idfilter2410—
wppo_litespeed_varyfilter2479@param ×2
wppo_litespeed_nextgen_rewritefilter2519@param ×1
wppo_litespeed_enable_nextgen_rewritefilter2527@param ×1
wppo_litespeed_nextgen_rewritefilter2558@param ×1
wppo_litespeed_enable_nextgen_rewritefilter2559@param ×1
wppo_litespeed_nextgen_rewritefilter2596@param ×1
wppo_litespeed_enable_nextgen_rewritefilter2597@param ×1
wppo_litespeed_brotlifilter2639@param ×1
wppo_litespeed_enable_brotlifilter2647@param ×1
wppo_litespeed_can_cdnfilter2679@param ×1
wppo_litespeed_strip_cache_controlfilter2714@param ×1