wppaste
WordPress

WP_Site_Health::get_test_persistent_object_cache(): array

Since
6.1.0
Source
wp-admin/includes/class-wp-site-health.php:2560
Tests if the site uses persistent object cache and recommends to use it if 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
The test result.

Performance profile

How much work a call to WP_Site_Health::get_test_persistent_object_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
49–93

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

Plugin surface
2 hooks

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

Called by
0

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

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 · 4 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_persistent_object_cache() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
wp_using_ext_object_cache()49__(), apply_filters(), __(), __(), __(), esc_url(), __(), __(), wp_using_ext_object_cache()
!wp_using_ext_object_cache() && !->should_suggest_persistent_object_cache()57__(), apply_filters(), __(), __(), __(), esc_url(), __(), __(), wp_using_ext_object_cache(), ->should_suggest_persistent_object_cache(), __()
!wp_using_ext_object_cache() && ->should_suggest_persistent_object_cache() && empty($available_services)83__(), apply_filters(), __(), __(), __(), esc_url(), __(), __(), wp_using_ext_object_cache(), ->should_suggest_persistent_object_cache(), ->available_object_cache_services(), __(), apply_filters(), __(), wp_kses()
!wp_using_ext_object_cache() && ->should_suggest_persistent_object_cache() && !empty($available_services)93__(), apply_filters(), __(), __(), __(), esc_url(), __(), __(), wp_using_ext_object_cache(), ->should_suggest_persistent_object_cache(), ->available_object_cache_services(), __(), __(), sprintf(), apply_filters(), __(), wp_kses()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10049–933
8.510049–933
8.410049–9334 fewer instructions than PHP 8.3
8.310449–973
8.210449–973
8.110449–973
7.410449–973

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::get_test_persistent_object_cache() runs, in this order:

  1. apply_filters( site_status_persistent_object_cache_url )filterline 2568 (+8 into the body)

    Filters the action URL for the persistent object cache health check.

  2. apply_filters( site_status_persistent_object_cache_notes )filterline 2630 (+70 into the body)

    Filters the second paragraph of the health check's description when suggesting the use of a persistent object cache.

Uses · 7

Source code

	public function get_test_persistent_object_cache() {		/**		 * Filters the action URL for the persistent object cache health check.		 *		 * @since 6.1.0		 *		 * @param string $action_url Learn more link for persistent object cache health check.		 */		$action_url = apply_filters(			'site_status_persistent_object_cache_url',			/* translators: Localized Support reference. */			__( 'https://developer.wordpress.org/advanced-administration/performance/optimization/#object-caching' )		); 		$result = array(			'test'        => 'persistent_object_cache',			'status'      => 'good',			'badge'       => array(				'label' => __( 'Performance' ),				'color' => 'blue',			),			'label'       => __( 'A persistent object cache is being used' ),			'description' => sprintf(				'<p>%s</p>',				__( 'A persistent object cache makes your site&#8217;s database more efficient, resulting in faster load times because WordPress can retrieve your site&#8217;s content and settings much more quickly.' )			),			'actions'     => sprintf(				'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',				esc_url( $action_url ),				__( 'Learn more about persistent object caching.' ),				/* translators: Hidden accessibility text. */				__( '(opens in a new tab)' )			),		); 		if ( wp_using_ext_object_cache() ) {			return $result;		} 		if ( ! $this->should_suggest_persistent_object_cache() ) {			$result['label'] = __( 'A persistent object cache is not required' ); 			return $result;		} 		$available_services = $this->available_object_cache_services(); 		$notes = __( 'Your hosting provider can tell you if a persistent object cache can be enabled on your site.' ); 		if ( ! empty( $available_services ) ) {			$notes .= ' ' . sprintf(				/* translators: Available object caching services. */				__( 'Your host appears to support the following object caching services: %s.' ),				implode( ', ', $available_services )			);		} 		/**		 * Filters the second paragraph of the health check's description		 * when suggesting the use of a persistent object cache.		 *		 * Hosts may want to replace the notes to recommend their preferred object caching solution.		 *		 * Plugin authors may want to append notes (not replace) on why object caching is recommended for their plugin.		 *		 * @since 6.1.0		 *		 * @param string   $notes              The notes appended to the health check description.		 * @param string[] $available_services The list of available persistent object cache services.		 */		$notes = apply_filters( 'site_status_persistent_object_cache_notes', $notes, $available_services ); 		$result['status']       = 'recommended';		$result['label']        = __( 'You should use a persistent object cache' );		$result['description'] .= sprintf(			'<p>%s</p>',			wp_kses(				$notes,				array(					'a'      => array( 'href' => true ),

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.