WP_Site_Health::get_page_cache_headers(): array<string,
- Since
- 6.1.0
- Source
wp-admin/includes/class-wp-site-health.php:3479
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
- Scaling
- Constant
- Instructions
- 4
- Plugin surface
- 1 hook
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 74.
Third-party callbacks on 'site_status_page_cache_supported_cache_headers' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 74 | 4 | 1 | |
| 8.5 | 74 | 4 | 1 | |
| 8.4 | 74 | 4 | 1 | 11 fewer instructions than PHP 8.3 |
| 8.3 | 85 | 7 | 1 | |
| 8.2 | 85 | 7 | 1 | |
| 8.1 | 85 | 7 | 1 | 54 more instructions than PHP 7.4 |
| 7.4 | 31 | 31 | 0 |
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:
- 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
- WP_Site_Health::check_for_page_caching()Checks if site has page cache enabled or not.
- WP_Site_Health::get_test_page_cache()Tests if a full page cache is available.
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-guideChangelog
Introduced in 6.1.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
array to array<string,.verified against sourceAbout 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.