includes/Integrations/class-litespeed-integration.php
LiteSpeed Integration class for the PerformanceOptimise plugin.
Class LiteSpeed_Integration
Class LiteSpeed_Integration
final class LiteSpeed_IntegrationConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
MODE_AUTO | public | \'auto\' | 37 |
MODE_WPPO | public | \'wppo\' | 45 |
MODE_LITESPEED | public | \'litespeed\' | 53 |
MODE_STANDALONE | public | \'standalone\' | 61 |
ALLOWED_MODES | private | array( self::MODE_AUTO, self::MODE_WPPO, self::MODE_LITESPEED, self::MODE_STANDALONE, ) | 69 |
PURGE_LOCK | private | \'wppo_litespeed_purge_lock\' | 85 |
PURGE_LOCK_TTL | private | 60 | 93 |
DB_QUEUE | public | \'wppo_litespeed_purge_queue\' | 620 |
TAG_QUEUE | private | \'wppo_lscache_tag_queue\' | 628 |
TAG_QUEUE_MAX | private | 100 | 636 |
DB_QUEUE_MAX | private | 200 | 644 |
DB_QUEUE_TTL | private | HOUR_IN_SECONDS | 652 |
Properties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$cached_effective_mode | private static | ?string | null | 103 |
$exclude_urls_memo | private static | ?array | null | 111 |
$cached_mode | private static | ?string | null | 119 |
$cached_is_litespeed | private static | ?bool | null | 127 |
$cached_is_lscache_active | private static | ?bool | null | 135 |
$cached_ttl | private static | ?int | null | 145 |
$cached_is_cacheable | private static | ?bool | null | 155 |
$cached_should_vary | private static | ?bool | null | 165 |
$cached_nextgen | private static | ?bool | null | 173 |
$cached_brotli | private static | ?bool | null | 181 |
$cached_can_cdn | private static | ?bool | null | 189 |
$uri_post_memo | private static | array | array() | 197 |
$purge_tags_memo | private static | ?array | null | 210 |
$hooks_registered | private static | bool | false | 220 |
$queue_shutdown_hooked | private static | bool | false | 660 |
$tag_buffer | private static | array | array() | 675 |
$tag_buffer_scopes | private static | array | array() | 683 |
publicstatic is_litespeed()
public static function is_litespeed(): boolWhether the current server is LiteSpeed / OpenLiteSpeed.
Return: bool — True if LiteSpeed or OpenLiteSpeed is detected.
publicstatic is_lscache_active()
public static function is_lscache_active(): boolWhether the LiteSpeed Cache plugin (LSCWP) is active.
Return: bool — True if LiteSpeed Cache plugin is active.
publicstatic get_mode()
public static function get_mode(): stringGet the configured LiteSpeed integration mode.
Return: string — One of self::MODE_* constants.
publicstatic effective_mode()
public static function effective_mode(): stringGet the effective (resolved) LiteSpeed integration mode.
Return: string — One of self::MODE_* concrete modes (never \’auto\’).
publicstatic is_wppo_cache_owner()
public static function is_wppo_cache_owner(): boolWhether WPPO owns the page cache (is the cache owner).
Return: bool — True if WPPO is the cache owner.
publicstatic should_disable_wppo_optimizer()
public static function should_disable_wppo_optimizer(): boolWhether WPPO should disable its optimizer (minify/combine/defer/delay).
Return: bool — True if WPPO optimizer should be disabled.
publicstatic is_purge_sync_enabled()
public static function is_purge_sync_enabled(): boolWhether purge sync is enabled (WPPO ↔ LSCache).
Return: bool — True if purges should be synced.
publicstatic get_purge_lock_key()
public static function get_purge_lock_key(): stringGet the blog-prefixed purge-lock transient key.
Return: string — Transient key.
publicstatic has_purge_lock()
public static function has_purge_lock(): boolWhether a purge-loop lock is currently active.
Return: bool — True if lock present.
publicstatic set_purge_lock()
public static function set_purge_lock(): voidSet the purge-loop lock for PURGE_LOCK_TTL seconds.
Return: void.
publicstatic sync_purge_all_to_litespeed()
public static function sync_purge_all_to_litespeed(): voidSync a WPPO \”purge all\” to LSCache.
Return: void.
publicstatic sync_purge_url_to_litespeed()
public static function sync_purge_url_to_litespeed(string $url_path): voidSync a WPPO single-page purge to LSCache via URL. Parameter Type Default Description $url_pathstring— URL path (e.g. \”/about/\”).
Return: void.
publicstatic sync_purge_post_to_litespeed()
public static function sync_purge_post_to_litespeed(int $post_id): voidSync a WPPO post invalidation to LSCache via post ID. Parameter Type Default Description $post_idint— Post ID.
Return: void.
publicstatic queue_purge_tags()
public static function queue_purge_tags(array $tags, string=\'public\' $scope): voidQueue LiteSpeed purge tags (P3). Parameter Type Default Description $tagsarray— Tag strings (e.g. Po.123, T.5, F). $scopestring=\'public\'— Scope: public|private|stale.
Return: void.
privatestatic maybe_hook_shutdown()
private static function maybe_hook_shutdown(): voidEnsure shutdown flush is hooked once.
Return: void.
publicstatic flush_tag_queue()
public static function flush_tag_queue(): voidFlush queued tags via X-LiteSpeed-Purge and litespeed_purge action.
Return: void.
privatestatic read_db_queue()
private static function read_db_queue(string $db_key): arrayRead the DB_QUEUE fallback option. Parameter Type Default Description $db_keystring— Option key (blog-prefixed).
Return: string[] — Valid queued tags.
privatestatic write_db_queue()
private static function write_db_queue(string $db_key, array $tags): voidPersist purge tags to the DB_QUEUE fallback option. Parameter Type Default Description $db_keystring— Option key (blog-prefixed). $tagsarray— Tags to persist.
Return: void.
publicstatic get_db_queue_key()
public static function get_db_queue_key(): stringGet DB queue option key (blog-prefixed).
Return: string.
publicstatic init()
public static function init(): voidInitialise LiteSpeed integration hooks.
Return: void.
publicstatic invalidate_uri_post_map()
public static function invalidate_uri_post_map(): voidInvalidate the URI-to-post-ID persistent map.
Return: void.
publicstatic handle_litespeed_purged_all()
public static function handle_litespeed_purged_all(): voidHandle LSCache \”purged all\” → clear WPPO file cache.
Return: void.
publicstatic handle_litespeed_purged_post()
public static function handle_litespeed_purged_post($post_id): voidHandle LSCache \”purged post\” → invalidate WPPO static HTML for post. Parameter Type Default Description $post_idint— Post ID purged by LSCache.
Return: void.
publicstatic handle_litespeed_purge_finalize()
public static function handle_litespeed_purge_finalize(): voidHandle LSCache purge finalize (catch-all) → clear WPPO cache.
Return: void.
privatestatic cached_uri_to_post_id()
private static function cached_uri_to_post_id(string $uri): intResolve a URI to a post ID using per-request + persistent caches. Parameter Type Default Description $uristring— Request URI.
Return: int — Post ID (0 when unresolvable).
privatestatic store_uri_to_post_id()
private static function store_uri_to_post_id(string $uri, int $post_id): voidStore a URI-to-post-ID resolution in per-request + persistent caches. Parameter Type Default Description $uristring— Request URI. $post_idint— Resolved post ID (0 for negative).
Return: void.
publicstatic get_litespeed_ttl()
public static function get_litespeed_ttl(?string=null $uri, =null $post_id): intGet LiteSpeed cache TTL in seconds mapped from cacheLife hours with per-context overrides. Parameter Type Default Description $uri?string=null— Optional URI for per-page TTL. $post_id=null— Optional post ID.
Return: int — TTL seconds (>=0, 0 = no-cache).
publicstatic is_request_cacheable()
public static function is_request_cacheable(): boolWhether current request is cacheable for LiteSpeed layer.
Return: bool — True if cacheable.
publicstatic should_vary_by_role()
public static function should_vary_by_role(): boolWhether vary-by-role should be added for LiteSpeed.
Return: bool — True if vary bridge should be active.
publicstatic get_vary_groups()
public static function get_vary_groups(): arrayGet active Vary groups (P2).
Return: array{role:bool,guest:bool,mobile:bool,webp:bool,commenter:bool,postpass:bool}.
publicstatic is_commenter_request()
public static function is_commenter_request(): boolWhether current request has a commenter cookie (LS-320).
Return: bool — True if commenter cookie present.
publicstatic is_postpass_request()
public static function is_postpass_request(): boolWhether current request has a post password cookie (LS-320).
Return: bool — True if postpass cookie present.
publicstatic is_private_request()
public static function is_private_request(): boolWhether current request should be treated as private/nocache (LS-320).
Return: bool — True if request should be private/nocache.
publicstatic seed_lscache_vary_cookie()
public static function seed_lscache_vary_cookie(): voidSeed _lscache_vary cookie for LSWS vary handshake (LS-320).
Return: void.
privatestatic get_vary_role_value()
private static function get_vary_role_value(): stringGet the vary role value — group 99 for admin (LSCWP parity).
Return: string — Role value (99 for admin, role hash otherwise).
privatestatic client_supports_webp()
private static function client_supports_webp(): boolWhether the current client supports WebP images.
Return: bool — True if Accept header contains image/webp or image/avif.
publicstatic clear_lscache_vary_cookie()
public static function clear_lscache_vary_cookie(): voidClear _lscache_vary cookie on logout.
Return: void.
privatestatic strip_crlf()
private static function strip_crlf(string $value): stringStrip CR/LF (and NUL) bytes from a value before it is passed to header(). Parameter Type Default Description $valuestring— Header value to clean.
Return: string — Value without header-breaking control characters.
publicstatic build_vary_header()
public static function build_vary_header(): stringBuild fallback vary header value from active groups (P2).
Return: string — Vary header value.
publicstatic handle_send_headers()
public static function handle_send_headers(): voidHandle send_headers — LS-native header emission (LS-301/302/304).
Return: void.
privatestatic send_litespeed_ttl()
private static function send_litespeed_ttl(int $ttl): voidSend LiteSpeed TTL header (public,max-age=N). Parameter Type Default Description $ttlint— TTL seconds.
Return: void.
privatestatic send_litespeed_nocache()
private static function send_litespeed_nocache(string $reason): voidSend LiteSpeed no-cache header for non-cacheable routes. Parameter Type Default Description $reasonstring— Reason for nocache (for LSCWP logging).
Return: void.
publicstatic get_litespeed_tags_for_purge()
public static function get_litespeed_tags_for_purge(): arrayBuild full LiteSpeed tag fan-out for current request.
Return: string[].
publicstatic invalidate_purge_tags_memo()
public static function invalidate_purge_tags_memo(): voidInvalidate the purge-tags memo.
Return: void.
publicstatic resolve_ttl_override_hours()
public static function resolve_ttl_override_hours($post_id, $post_type, bool $is_singular_ctx, $overrides): ?intResolve per-post-type TTL override hours (pure). Parameter Type Default Description $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.
publicstatic map_hours_to_seconds()
public static function map_hours_to_seconds(int $hours): intMap cacheLife hours to TTL seconds (pure). Parameter Type Default Description $hoursint— CacheLife hours.
Return: int — TTL seconds.
publicstatic build_litespeed_tags()
public static function build_litespeed_tags(array $facts): arrayBuild the LiteSpeed tag fan-out from resolved facts (pure). Parameter Type Default Description $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).
privatestatic compute_litespeed_tags_for_purge()
private static function compute_litespeed_tags_for_purge(): arrayCompute the full LiteSpeed tag fan-out for the current request.
Return: string[].
privatestatic send_litespeed_tags()
private static function send_litespeed_tags(): voidSend LiteSpeed tag headers (WPPO + full fan-out).
Return: void.
publicstatic filter_litespeed_vary()
public static function filter_litespeed_vary($vary)Filter litespeed_vary — append wppo_role_hash when vary bridge active. Parameter Type Default Description $varymixed— Vary value from LSCWP (array|string).
Return: mixed — Modified vary value.
publicstatic is_nextgen_rewrite_enabled()
public static function is_nextgen_rewrite_enabled(): boolWhether next-gen Vary:Accept rewrite is enabled (LS-401).
Return: bool — True if next-gen rewrite should be active.
publicstatic is_nextgen_rewrite_enabled_for_nginx()
public static function is_nextgen_rewrite_enabled_for_nginx(): boolWhether next-gen rewrite is enabled for Nginx/server_rules context (LS-402).
Return: bool — True if nginx next-gen map should be included.
publicstatic is_nextgen_rewrite_enabled_for_apache()
public static function is_nextgen_rewrite_enabled_for_apache(): boolWhether next-gen rewrite is enabled for Apache/.htaccess context.
Return: bool — True if the htaccess next-gen block should be included.
publicstatic is_brotli_enabled()
public static function is_brotli_enabled(): boolWhether Brotli .br generation is enabled (LS-403).
Return: bool — True if brotli generation should run.
publicstatic can_apply_cdn()
public static function can_apply_cdn(): boolWhether CDN rewriting is allowed by LiteSpeed guard (LS-404).
Return: bool — True if CDN rewriting may proceed.
privatestatic maybe_strip_generic_cache_control()
private static function maybe_strip_generic_cache_control(): voidStrip generic Cache-Control when LS public header sent (LS-304).
Return: void.
publicstatic reset_cache()
public static function reset_cache(): voidReset all per-request caches (for testing).
Return: void.
publicstatic get_info()
public static function get_info(): arrayGet 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 }.
Hooks
Hooks referenced in includes/Integrations/class-litespeed-integration.php: Hook Type Line Notes wppo_litespeed_is_litespeedfilter 250 @param ×1 wppo_litespeed_is_lscache_activefilter 315 @param ×1 wppo_litespeed_modefilter 348 @param ×1 wppo_litespeed_effective_modefilter 420 @param ×2 wppo_litespeed_should_disable_optimizerfilter 485 @param ×2 wppo_litespeed_purge_syncfilter 515 @param ×1 wppo_litespeed_purge_tagsfilter 735 @param ×2 wppo_litespeed_purge_tag_stringfilter 829 @param ×2 wppo_cache_ttlfilter 1330 @param ×3 wppo_litespeed_ttlfilter 1340 @param ×3 wppo_litespeed_is_cacheablefilter 1382 @param ×1 wppo_litespeed_is_cacheablefilter 1460 @param ×1 wppo_litespeed_vary_enabledfilter 1507 @param ×1 wppo_litespeed_vary_groupsfilter 1541 @param ×1 wppo_litespeed_lscache_vary_valuefilter 1687 @param ×2 wppo_litespeed_vary_headerfilter 1849 @param ×2 wppo_litespeed_vary_fallbackfilter 1972 @param ×1 wppo_litespeed_ttlfilter 1997 @param ×1 wppo_litespeed_cache_control_headerfilter 2011 @param ×2 wppo_litespeed_nocache_reasonfilter 2039 @param ×1 wppo_litespeed_nocache_headerfilter 2060 @param ×2 wppo_litespeed_tag_post_idfilter 2269 — wppo_litespeed_tagfilter 2383 @param ×1 wppo_litespeed_tag_post_idfilter 2410 — wppo_litespeed_varyfilter 2479 @param ×2 wppo_litespeed_nextgen_rewritefilter 2519 @param ×1 wppo_litespeed_enable_nextgen_rewritefilter 2527 @param ×1 wppo_litespeed_nextgen_rewritefilter 2558 @param ×1 wppo_litespeed_enable_nextgen_rewritefilter 2559 @param ×1 wppo_litespeed_nextgen_rewritefilter 2596 @param ×1 wppo_litespeed_enable_nextgen_rewritefilter 2597 @param ×1 wppo_litespeed_brotlifilter 2639 @param ×1 wppo_litespeed_enable_brotlifilter 2647 @param ×1 wppo_litespeed_can_cdnfilter 2679 @param ×1 wppo_litespeed_strip_cache_controlfilter 2714 @param ×1