wppaste
WordPress

WP_Site_Health::get_test_page_cache(): array

Since
6.1.0
Source
wp-admin/includes/class-wp-site-health.php:2446
Tests if a full page cache is available.

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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
88–150

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 238.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_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.

WhenInstructionsCalls 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

PHPCompiledExecutedBranchesNotes
8.6-dev23888–15012
8.523888–15012
8.423888–150129 fewer instructions than PHP 8.3
8.324791–15912
8.224791–159121 more instruction than PHP 8.1
8.124691–15812
7.424691–15812

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

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.

  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.

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.