WP_Site_Health::should_suggest_persistent_object_cache(): bool
- Since
- 6.1.0
- Source
wp-admin/includes/class-wp-site-health.php:3584
Compatibility
- WordPress
- since 6.1.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 9–76
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via ->get_results().
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 82.
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.
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 - serializeserialisation
serialize()called directly - sqldatabase query
->get_results()called directly - cacheobject cache
wp_cache_get()one call below WP_Site_Health::should_suggest_persistent_object_cache()
What one call costs · 5 distinct outcomes
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.
| When | Instructions | Calls it makes |
|---|---|---|
is_bool($short_circuit) | 9 | apply_filters() |
!is_bool($short_circuit) && is_multisite() | 12 | apply_filters(), is_multisite() |
!is_bool($short_circuit) && !is_multisite() | 24 | apply_filters(), is_multisite(), apply_filters(), wp_load_alloptions() |
!is_bool($short_circuit) && !is_multisite() | 31 | apply_filters(), is_multisite(), apply_filters(), wp_load_alloptions(), serialize() |
!is_bool($short_circuit) && !is_multisite() | 69–76 | apply_filters(), is_multisite(), apply_filters(), wp_load_alloptions(), serialize(), ->prepare(), ->get_results() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 82 | 9–76 | 7 | |
| 8.5 | 82 | 9–76 | 7 | |
| 8.4 | 82 | 9–76 | 7 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 86 | 9–80 | 7 | |
| 8.2 | 86 | 9–80 | 7 | |
| 8.1 | 86 | 9–80 | 7 | |
| 7.4 | 86 | 9–80 | 7 |
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:
- apply_filters( site_status_should_suggest_persistent_object_cache )filterline 3597 (+13 into the body)
Filters whether to suggest use of a persistent object cache and bypass default threshold checks.
- apply_filters( site_status_persistent_object_cache_thresholds )filterline 3613 (+29 into the body)
Filters the thresholds used to determine whether to suggest the use of a persistent object cache.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_multisite()Determines whether Multisite is enabled.
- wp_load_alloptions()Loads and caches all autoloaded options, if available or all options.
Used by · 1
- WP_Site_Health::get_test_persistent_object_cache()Tests if the site uses persistent object cache and recommends to use it if not.
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, ); foreach ( $threshold_map as $threshold => $table ) { if ( $thresholds[ $threshold ] <= $results[ $table ]->rows ) { return true; } } return false; }Changelog
Introduced in 6.1.0. Unchanged from 6.7.10 through 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.10 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.