WP_Site_Health::check_for_page_caching(): WP_Error|array
- Since
- 6.1.0
- Source
wp-admin/includes/class-wp-site-health.php:3612
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
WP_Error|array- Page cache detection details or else error information.
$advanced_cache_presentboolWhether a page cache plugin is present.$page_caching_response_headersarray[]Sets of client caching headers for the responses.$response_timingfloat[]Response timings.
Performance profile
How much work a call to WP_Site_Health::check_for_page_caching() 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
- Expensive
- Scaling
- Scales with input
- Instructions
- 32–86
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches an outbound HTTP request via wp_remote_get().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 143.
Third-party callbacks on 'https_local_ssl_verify', 'enable_loading_advanced_cache_dropin' run inside this call, and their cost is not bounded by anything here.
1 place 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 - httpoutbound HTTP request
wp_remote_get()called directly - filesystemfilesystem access
file_exists()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::check_for_page_caching() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && !$i | 32–39 | home_url(), apply_filters(), ->get_page_cache_headers(), file_exists() |
!isset($value) && !$i && file_exists() && defined('WP_CACHE') | 41–44 | home_url(), apply_filters(), ->get_page_cache_headers(), file_exists(), apply_filters() |
!isset($value) && $i && is_wp_error() | 47–50 | home_url(), apply_filters(), ->get_page_cache_headers(), microtime(), home_url(), compact(), wp_remote_get(), microtime(), is_wp_error() |
isset($value) && !$i | 55–59 | home_url(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), ->get_page_cache_headers(), file_exists() |
!isset($value) && $i && !is_wp_error() | 63–66 | home_url(), apply_filters(), ->get_page_cache_headers(), microtime(), home_url(), compact(), wp_remote_get(), microtime(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message() |
isset($value) && !$i && file_exists() && defined('WP_CACHE') | 64 | home_url(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), ->get_page_cache_headers(), file_exists(), apply_filters() |
isset($value) && $i && is_wp_error() | 70 | home_url(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), ->get_page_cache_headers(), microtime(), home_url(), compact(), wp_remote_get(), microtime(), is_wp_error() |
isset($value) && $i && !is_wp_error() | 86 | home_url(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), ->get_page_cache_headers(), microtime(), home_url(), compact(), wp_remote_get(), microtime(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 143 instructions, 32–86 executed per call, 14 branches. The work does not change between versions.
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 · 2
2 hooks fire while WP_Site_Health::check_for_page_caching() runs, in this order:
- apply_filters( https_local_ssl_verify )filterline 3615 (+3 into the body)
Filters whether SSL should be verified for local HTTP API requests.
- apply_filters( enable_loading_advanced_cache_dropin )filterline 3671 (+59 into the body)
Filters whether to enable loading of the advanced-cache.php drop-in.
Uses · 10
- apply_filters()Calls the callback functions that have been added to a filter hook.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- wp_remote_get()Performs an HTTP request using the GET method and returns its response.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_remote_retrieve_response_code()Retrieves only the response code from the raw response.
- wp_remote_retrieve_response_message()Retrieves only the response message from the raw response.
- wp_remote_retrieve_header()Retrieves a single header by name from the raw response.
- WP_Site_Health::get_page_cache_headers()Returns a mapping from response headers to an optional callback to verify if page cache is enabled or not.
- WP_Error::__construct()Initializes the error.
Used by · 1
- WP_Site_Health::get_page_cache_detail()Gets page cache details.
Source code
private function check_for_page_caching() { /** This filter is documented in wp-includes/class-wp-http-streams.php */ $sslverify = apply_filters( 'https_local_ssl_verify', false, home_url( '/' ) ); $headers = array(); /* * Include basic auth in loopback requests. Note that this will only pass along basic auth when user is * initiating the test. If a site requires basic auth, the test will fail when it runs in WP Cron as part of * wp_site_health_scheduled_check. This logic is copied from WP_Site_Health::can_perform_loopback(). */ if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); } $caching_headers = $this->get_page_cache_headers(); $page_caching_response_headers = array(); $response_timing = array(); for ( $i = 1; $i <= 3; $i++ ) { $start_time = microtime( true ); $http_response = wp_remote_get( home_url( '/' ), compact( 'sslverify', 'headers' ) ); $end_time = microtime( true ); if ( is_wp_error( $http_response ) ) { return $http_response; } if ( wp_remote_retrieve_response_code( $http_response ) !== 200 ) { return new WP_Error( 'http_' . wp_remote_retrieve_response_code( $http_response ), wp_remote_retrieve_response_message( $http_response ) ); } $response_headers = array(); foreach ( $caching_headers as $header => $callback ) { $header_values = wp_remote_retrieve_header( $http_response, $header ); if ( empty( $header_values ) ) { continue; } $header_values = (array) $header_values; if ( empty( $callback ) || ( is_callable( $callback ) && count( array_filter( $header_values, $callback ) ) > 0 ) ) { $response_headers[ $header ] = $header_values; } } $page_caching_response_headers[] = $response_headers; $response_timing[] = ( $end_time - $start_time ) * 1000; } return array( 'advanced_cache_present' => ( file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) && ( defined( 'WP_CACHE' ) && WP_CACHE ) && /** This filter is documented in wp-settings.php */ apply_filters( 'enable_loading_advanced_cache_dropin', true ) ), 'page_caching_response_headers' => $page_caching_response_headers, 'response_timing' => $response_timing, ); }Changelog
Introduced in 6.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
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.