WP_Site_Health::get_test_page_cache(): array
- Since
- 6.1.0
- Source
wp-admin/includes/class-wp-site-health.php:2446
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- The test result.
Performance profile
How much work a call to WP_Site_Health::get_test_page_cache() 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
- 88–150
- Plugin surface
- None
- Called by
- 0
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, depending on the branch taken. The body compiles to 238.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below WP_Site_Health::get_test_page_cache()
Further down the call graph this can also reach query, option, cache, serialize 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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::get_test_page_cache() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 88 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), __(), ->get_error_message(), ->get_error_code(), sprintf(), wp_kses_post() |
!is_wp_error() && !$page_cache_detail && is_array($page_cache_detail) | 91–100 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), __() |
!is_wp_error() && empty($page_cache_detail) | 94–106 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), __(), __() |
!is_wp_error() && !$page_cache_detail && is_array($page_cache_detail) | 118–128 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), ->get_good_response_time_threshold(), __(), number_format_i18n(), number_format_i18n(), sprintf(), __() |
!is_wp_error() | 121–134 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), ->get_good_response_time_threshold(), __(), number_format_i18n(), number_format_i18n(), sprintf(), __(), __() |
!is_wp_error() && !empty($page_cache_detail) && !$page_cache_detail && is_array($page_cache_detail) | 134–144 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), ->get_good_response_time_threshold(), __(), number_format_i18n(), number_format_i18n(), sprintf(), _n(), sprintf() |
!is_wp_error() && !empty($page_cache_detail) | 137–150 | __(), __(), ->get_page_cache_headers(), array_keys(), __(), wp_kses_post(), __(), __(), __(), sprintf(), ->get_page_cache_detail(), is_wp_error(), __(), ->get_good_response_time_threshold(), __(), number_format_i18n(), number_format_i18n(), sprintf(), _n(), sprintf(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 238 | 88–150 | 12 | |
| 8.5 | 238 | 88–150 | 12 | |
| 8.4 | 238 | 88–150 | 12 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 247 | 91–159 | 12 | |
| 8.2 | 247 | 91–159 | 12 | 1 more instruction than PHP 8.1 |
| 8.1 | 246 | 91–158 | 12 | |
| 7.4 | 246 | 91–158 | 12 |
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.
Uses · 8
- __()Retrieves the translation of $text.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- number_format_i18n()Converts float number to format based on the locale.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- 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_Site_Health::get_page_cache_detail()Gets page cache details.
- WP_Site_Health::get_good_response_time_threshold()Gets the threshold below which a response time is considered good.
Source code
public function get_test_page_cache() { $description = '<p>' . __( 'Page cache enhances the speed and performance of your site by saving and serving static pages instead of calling for a page every time a user visits.' ) . '</p>'; $description .= '<p>' . __( 'Page cache is detected by looking for an active page cache plugin as well as making three requests to the homepage and looking for one or more of the following HTTP client caching response headers:' ) . '</p>'; $description .= '<code>' . implode( '</code>, <code>', array_keys( $this->get_page_cache_headers() ) ) . '.</code>'; $result = array( 'badge' => array( 'label' => __( 'Performance' ), 'color' => 'blue', ), 'description' => wp_kses_post( $description ), 'test' => 'page_cache', 'status' => 'good', 'label' => '', 'actions' => sprintf( '<p><a href="%1$s" target="_blank" rel="noreferrer">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>', __( 'https://developer.wordpress.org/advanced-administration/performance/optimization/#caching' ), __( 'Learn more about page cache' ), /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ), ); $page_cache_detail = $this->get_page_cache_detail(); if ( is_wp_error( $page_cache_detail ) ) { $result['label'] = __( 'Unable to detect the presence of page cache' ); $result['status'] = 'recommended'; $error_info = sprintf( /* translators: 1: Error message, 2: Error code. */ __( 'Unable to detect page cache due to possible loopback request problem. Please verify that the loopback request test is passing. Error: %1$s (Code: %2$s)' ), $page_cache_detail->get_error_message(), $page_cache_detail->get_error_code() ); $result['description'] = wp_kses_post( "<p>$error_info</p>" ) . $result['description']; return $result; } $result['status'] = $page_cache_detail['status']; switch ( $page_cache_detail['status'] ) { case 'recommended': $result['label'] = __( 'Page cache is not detected but the server response time is OK' ); break; case 'good': $result['label'] = __( 'Page cache is detected and the server response time is good' ); break; default: if ( empty( $page_cache_detail['headers'] ) && ! $page_cache_detail['advanced_cache_present'] ) { $result['label'] = __( 'Page cache is not detected and the server response time is slow' ); } else { $result['label'] = __( 'Page cache is detected but the server response time is still slow' ); } } $page_cache_test_summary = array(); if ( empty( $page_cache_detail['response_time'] ) ) { $page_cache_test_summary[] = '<span class="dashicons dashicons-dismiss" aria-hidden="true"></span> ' . __( 'Server response time could not be determined. Verify that loopback requests are working.' ); } else { $threshold = $this->get_good_response_time_threshold(); if ( $page_cache_detail['response_time'] < $threshold ) { $page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt" aria-hidden="true"></span> ' . sprintf( /* translators: 1: The response time in milliseconds, 2: The recommended threshold in milliseconds. */ __( 'Median server response time was %1$s milliseconds. This is less than the recommended %2$s milliseconds threshold.' ), number_format_i18n( $page_cache_detail['response_time'] ), number_format_i18n( $threshold ) ); } else { $page_cache_test_summary[] = '<span class="dashicons dashicons-warning" aria-hidden="true"></span> ' . sprintf( /* translators: 1: The response time in milliseconds, 2: The recommended threshold in milliseconds. */ __( 'Median server response time was %1$s milliseconds. It should be less than the recommended %2$s milliseconds threshold.' ), number_format_i18n( $page_cache_detail['response_time'] ), number_format_i18n( $threshold ) ); } if ( empty( $page_cache_detail['headers'] ) ) { $page_cache_test_summary[] = '<span class="dashicons dashicons-warning" aria-hidden="true"></span> ' . __( 'No client caching response headers were detected.' );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.