wppaste
WordPress

WP_Site_Health::get_page_cache_headers(): array<string,

Since
6.1.0
Source
wp-admin/includes/class-wp-site-health.php:3479
Returns a mapping from response headers to an optional callback to verify if page cache is enabled or not.

Compatibility

WordPress
since 6.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

array<string,
?callable> Mapping of page caching headers and their (optional) verification callbacks.
A null value means a simple existence check is used for the header.

Performance profile

How much work a call to WP_Site_Health::get_page_cache_headers() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
4

Executed per call on PHP 8.5. The body compiles to 74.

Plugin surface
1 hook

Third-party callbacks on 'site_status_page_cache_supported_cache_headers' run inside this call, and their cost is not bounded by anything here.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::get_page_cache_headers() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always4none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7441
8.57441
8.4744111 fewer instructions than PHP 8.3
8.38571
8.28571
8.1857154 more instructions than PHP 7.4
7.431310

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Site_Health::get_page_cache_headers() runs, in this order:

  1. apply_filters( site_status_page_cache_supported_cache_headers )filterline 3596 (+117 into the body)

    Filters the list of cache headers supported by core.

Uses · 1

  • apply_filters()Calls the callback functions that have been added to a filter hook.

Used by · 2

Source code

	public function get_page_cache_headers(): array { 		$cache_hit_callback = static function ( $header_value ) {			return 1 === preg_match( '/(^| |,)HIT(,| |$)/i', $header_value );		}; 		$cache_headers = array(			// Standard HTTP caching headers.			'cache-control'          => static function ( $header_value ) {				return (bool) preg_match( '/max-age=[1-9]/', $header_value );			},			'expires'                => static function ( $header_value ) {				return strtotime( $header_value ) > time();			},			'age'                    => static function ( $header_value ) {				return is_numeric( $header_value ) && $header_value > 0;			},			'last-modified'          => null,			'etag'                   => null,			'via'                    => null, 			/**			 * Custom caching headers.			 *			 * These do not seem to be actually used by any caching layers. There were first introduced in a Site Health			 * test in the AMP plugin. They were copied into the Performance Lab plugin's Site Health test before they			 * were merged into core.			 *			 * @link https://github.com/ampproject/amp-wp/pull/6849			 * @link https://github.com/WordPress/performance/pull/263			 * @link https://core.trac.wordpress.org/changeset/54043			 */			'x-cache-enabled'        => static function ( $header_value ) {				return ( 'true' === strtolower( $header_value ) );			},			'x-cache-disabled'       => static function ( $header_value ) {				return ( 'on' !== strtolower( $header_value ) );			}, 			/**			 * CloudFlare.			 *			 * @link https://developers.cloudflare.com/cache/concepts/cache-responses/			 */			'cf-cache-status'        => $cache_hit_callback, 			/**			 * Fastly.			 *			 * @link https://www.fastly.com/documentation/reference/http/http-headers/X-Cache/			 */			'x-cache'                => $cache_hit_callback, 			/**			 * LightSpeed.			 *			 * @link https://docs.litespeedtech.com/lscache/devguide/controls/#x-litespeed-cache			 */			'x-litespeed-cache'      => $cache_hit_callback, 			/**			 * OpenResty srcache-nginx-module.			 *			 * The `x-srcache-store-status` header indicates if the response was stored in the cache.			 * Valid values include `STORE` and `BYPASS`.			 *			 * The `x-srcache-fetch-status` header indicates if the response was fetched from the cache.			 * Valid values include `HIT`, `MISS`, and `BYPASS`.			 *			 * @link https://github.com/openresty/srcache-nginx-module			 */			'x-srcache-store-status' => static function ( $header_value ) {				return 'store' === strtolower( $header_value );			},			'x-srcache-fetch-status' => $cache_hit_callback, 			/**			 * Nginx.			 *			 * @link https://blog.nginx.org/blog/nginx-caching-guide

Changelog

Introduced in 6.1.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Return type changed from array to array<string,.verified against source
6.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-wp-site-health.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.