Optimize HTML cache pipeline for minimum latency and maximum throughput (PHP 8.3+)#203
Draft
Optimize HTML cache pipeline for minimum latency and maximum throughput (PHP 8.3+)#203
Conversation
Co-authored-by: Jumaron <41344875+Jumaron@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize HTML cache for better latency and throughput
Optimize HTML cache pipeline for minimum latency and maximum throughput (PHP 8.3+)
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HTML cache drop-in lacked pre-compressed serving, critical HTTP caching headers, and several correctness issues that left performance and browser/CDN cacheability on the table. The cache lifetime was also hardcoded at 3600 s in the drop-in, ignoring the admin setting.
advanced-cache-template.php— hot path (every cached request)index.html.gzdirectly whenAccept-Encoding: gzipis present and the file exists, eliminating per-request compression CPU entirely. Disableszlib.output_compressionto prevent double-encoding.Last-Modified,Expires,Content-Length,Vary: Accept-Encoding.If-Modified-Sincesupport: 304 on date-based conditional GETs, not just ETag. Fixed comparison to<(not<=)."<hex-mtime>-<hex-size>"— includes file size so same-second rewrites invalidate correctly.WPSC_CACHE_DIR/config.php(written by plugin on activation/save) socache_lifetimetracks the admin setting.str_starts_with/str_contains/str_ends_with;is_file()overfile_exists();parse_urlfalse-safety (?:not??).HTMLCache.php— write path (once per uncached request).html.gzalongside.html:gzencode($content, 6)viaatomicWrite, so the drop-in always has a pre-compressed sibling to serve.preg_replacenull-return guarded to avoid content corruption on invalid UTF-8.text/htmlcontent-type guard: skips caching JSON/XML/REST responses.libxml_use_internal_errorsleak: saves and restores previous state; was permanently silencing libxml errors for the remainder of the request.BYPASS_PARAMS,MAX_QUERY_LEN,IGNORED_EXTENSIONS.AbstractCacheDriver.phpLOCK_EXadded tofile_put_contentsinatomicWritefor safer concurrent writes.Plugin.phpinstallAdvancedCache()always overwrites: was a no-op after first install, silently leaving a stale drop-in after plugin updates.writeAdvancedCacheConfig(): serialises['cache_lifetime' => N]toWPSC_CACHE_DIR/config.phpusingvar_export + LOCK_EX. Called on activation and onwpscac_settings_updated→refreshServerConfig(). Logs failure underWP_DEBUG.Original prompt
Created from VS Code.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.