wppaste
WordPress

WP_Site_Health::should_suggest_persistent_object_cache(): bool

Since
6.1.0
Source
wp-admin/includes/class-wp-site-health.php:3756
Determines whether to suggest using a persistent object cache.

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

bool
Whether to suggest using a persistent object cache.

Performance profile

How much work a call to WP_Site_Health::should_suggest_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
Light

Only touches the object cache, via wp_cache_get().

Scaling
Constant

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

Instructions
9

Executed per call on PHP 8.5. The body compiles to 87.

Plugin surface
2 hooks

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

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP_Site_Health::should_suggest_persistent_object_cache()

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

WhenInstructionsCalls it makes
always9none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8794
8.58794
8.487944 fewer instructions than PHP 8.3
8.39194
8.29194
8.191949 more instructions than PHP 7.4
7.4829–784

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

  1. apply_filters( site_status_should_suggest_persistent_object_cache )filterline 3769 (+13 into the body)

    Filters whether to suggest use of a persistent object cache and bypass default threshold checks.

  2. apply_filters( site_status_persistent_object_cache_thresholds )filterline 3785 (+29 into the body)

    Filters the thresholds used to determine whether to suggest the use of a persistent object cache.

Uses · 4

Used by · 1

Source code

	public function should_suggest_persistent_object_cache() {		global $wpdb; 		/**		 * Filters whether to suggest use of a persistent object cache and bypass default threshold checks.		 *		 * Using this filter allows to override the default logic, effectively short-circuiting the method.		 *		 * @since 6.1.0		 *		 * @param bool|null $suggest Boolean to short-circuit, for whether to suggest using a persistent object cache.		 *                           Default null.		 */		$short_circuit = apply_filters( 'site_status_should_suggest_persistent_object_cache', null );		if ( is_bool( $short_circuit ) ) {			return $short_circuit;		} 		if ( is_multisite() ) {			return true;		} 		/**		 * Filters the thresholds used to determine whether to suggest the use of a persistent object cache.		 *		 * @since 6.1.0		 *		 * @param int[] $thresholds The list of threshold numbers keyed by threshold name.		 */		$thresholds = apply_filters(			'site_status_persistent_object_cache_thresholds',			array(				'alloptions_count' => 500,				'alloptions_bytes' => 100000,				'comments_count'   => 1000,				'options_count'    => 1000,				'posts_count'      => 1000,				'terms_count'      => 1000,				'users_count'      => 1000,			)		); 		$alloptions = wp_load_alloptions(); 		if ( $thresholds['alloptions_count'] < count( $alloptions ) ) {			return true;		} 		if ( $thresholds['alloptions_bytes'] < strlen( serialize( $alloptions ) ) ) {			return true;		} 		$table_names = implode( "','", array( $wpdb->comments, $wpdb->options, $wpdb->posts, $wpdb->terms, $wpdb->users ) ); 		// With InnoDB the `TABLE_ROWS` are estimates, which are accurate enough and faster to retrieve than individual `COUNT()` queries.		$results = $wpdb->get_results(			$wpdb->prepare(				// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- This query cannot use interpolation.				"SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND TABLE_NAME IN ('$table_names') GROUP BY TABLE_NAME;",				DB_NAME			),			OBJECT_K		); 		$threshold_map = array(			'comments_count' => $wpdb->comments,			'options_count'  => $wpdb->options,			'posts_count'    => $wpdb->posts,			'terms_count'    => $wpdb->terms,			'users_count'    => $wpdb->users,		); 		return array_any( $threshold_map, fn( $table, $threshold ) => $thresholds[ $threshold ] <= $results[ $table ]->rows );	}

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.