From 24a96cd044047a1fddda4e02bda8aafc1c090226 Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Mon, 14 Jul 2025 09:55:23 +0800 Subject: [PATCH 01/31] OPcache: Add information to the Site Health -> Server --- src/wp-admin/includes/class-wp-debug-data.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index cd04297684bcd..06252cfc2eca0 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -471,6 +471,64 @@ private static function get_wp_server(): array { 'debug' => $imagick_loaded, ); + // OPCache. + $opcache_loaded = extension_loaded( 'opcache' ); + + $fields['opcache_availability'] = array( + 'label' => __( 'Is the OPcache extension available?' ), + 'value' => ( $opcache_loaded ? __( 'Yes' ) : __( 'No' ) ), + 'debug' => $opcache_loaded, + ); + + if ( $opcache_loaded && function_exists( 'opcache_get_status' ) ) { + $opcache_status = opcache_get_status( false ); + + if ( $opcache_status ) { + $fields['opcache_enabled'] = array( + 'label' => __( 'OPcache' ), + 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), + 'debug' => $opcache_status['opcache_enabled'], + ); + + $fields['opcache_memory_usage'] = array( + 'label' => __( 'OPcache memory usage' ), + 'value' => sprintf( + /* translators: 1: Used memory, 2: Total memory */ + __( '%1$s of %2$s' ), + size_format( $opcache_status['memory_usage']['used_memory'] ), + size_format( $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] ) + ), + 'debug' => sprintf( + '%s of %s', + $opcache_status['memory_usage']['used_memory'], + $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] + ), + ); + + $fields['opcache_hit_rate'] = array( + 'label' => __( 'OPcache hit rate' ), + 'value' => sprintf( + /* translators: %s: Hit rate percentage */ + __( '%s%%' ), + round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) + ), + 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], + ); + + $fields['opcache_cached_scripts'] = array( + 'label' => __( 'OPcache cached scripts' ), + 'value' => number_format_i18n( $opcache_status['opcache_statistics']['num_cached_scripts'] ), + 'debug' => $opcache_status['opcache_statistics']['num_cached_scripts'], + ); + + $fields['opcache_cached_keys'] = array( + 'label' => __( 'OPcache cached keys' ), + 'value' => number_format_i18n( $opcache_status['opcache_statistics']['num_cached_keys'] ), + 'debug' => $opcache_status['opcache_statistics']['num_cached_keys'], + ); + } + } + // Pretty permalinks. $pretty_permalinks_supported = got_url_rewrite(); From b53015801659d0b8cdccc98c98942125ba2b0b3f Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Thu, 17 Jul 2025 17:37:04 +0800 Subject: [PATCH 02/31] Add Site HEalth test --- src/wp-admin/includes/class-wp-debug-data.php | 6 +-- .../includes/class-wp-site-health.php | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 06252cfc2eca0..367e7de83bd29 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -471,8 +471,8 @@ private static function get_wp_server(): array { 'debug' => $imagick_loaded, ); - // OPCache. - $opcache_loaded = extension_loaded( 'opcache' ); + // Opcode Cache. + $opcache_loaded = extension_loaded( 'Zend OPcache' ); $fields['opcache_availability'] = array( 'label' => __( 'Is the OPcache extension available?' ), @@ -482,7 +482,7 @@ private static function get_wp_server(): array { if ( $opcache_loaded && function_exists( 'opcache_get_status' ) ) { $opcache_status = opcache_get_status( false ); - + if ( $opcache_status ) { $fields['opcache_enabled'] = array( 'label' => __( 'OPcache' ), diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index b7847d5e310a8..64ef8f25eadf6 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2687,6 +2687,56 @@ public function get_test_autoloaded_options() { return $result; } + __( 'OPcache is enabled' ), + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '

%s

', + __( 'OPcache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) + ), + 'actions' => sprintf( + '

%s %s

', + 'https://www.php.net/manual/en/book.opcache.php', + __( 'Learn more about OPcache.' ), + /* translators: Hidden accessibility text. */ + __( '(opens in a new tab)' ) + ), + 'test' => 'opcache', + ); + + if ( $opcache_loaded ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'OPcache is not available' ); + $result['description'] .= '

' . __( 'OPcache is not installed or enabled on your server. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; + } elseif ( ! $opcache_enabled ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'OPcache is installed but not enabled' ); + $result['description'] .= '

' . __( 'OPcache is installed but not enabled. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; + } + + return $result; +} + /** * Returns a set of tests that belong to the site status page. * @@ -2775,6 +2825,10 @@ public static function get_tests() { 'label' => __( 'Autoloaded options' ), 'test' => 'autoloaded_options', ), + 'opcache' => array( + 'label' => __( 'OPcache' ), + 'test' => 'opcache', + ), ), 'async' => array( 'dotorg_communication' => array( From 231515b899b090dfca3d4e496523e2bcc15fdeb2 Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Thu, 24 Jul 2025 09:58:33 +0800 Subject: [PATCH 03/31] Update: Remove scripts and keys + use functions_exists() for consistent check --- src/wp-admin/includes/class-wp-debug-data.php | 28 +------ .../includes/class-wp-site-health.php | 74 +++++++++---------- 2 files changed, 38 insertions(+), 64 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 367e7de83bd29..3dbc933707060 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -472,26 +472,18 @@ private static function get_wp_server(): array { ); // Opcode Cache. - $opcache_loaded = extension_loaded( 'Zend OPcache' ); - - $fields['opcache_availability'] = array( - 'label' => __( 'Is the OPcache extension available?' ), - 'value' => ( $opcache_loaded ? __( 'Yes' ) : __( 'No' ) ), - 'debug' => $opcache_loaded, - ); - - if ( $opcache_loaded && function_exists( 'opcache_get_status' ) ) { + if ( function_exists( 'opcache_get_status' ) ) { $opcache_status = opcache_get_status( false ); if ( $opcache_status ) { $fields['opcache_enabled'] = array( - 'label' => __( 'OPcache' ), + 'label' => __( 'Opcode cache' ), 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), 'debug' => $opcache_status['opcache_enabled'], ); $fields['opcache_memory_usage'] = array( - 'label' => __( 'OPcache memory usage' ), + 'label' => __( 'Opcode cache memory usage' ), 'value' => sprintf( /* translators: 1: Used memory, 2: Total memory */ __( '%1$s of %2$s' ), @@ -506,7 +498,7 @@ private static function get_wp_server(): array { ); $fields['opcache_hit_rate'] = array( - 'label' => __( 'OPcache hit rate' ), + 'label' => __( 'Opcode cache hit rate' ), 'value' => sprintf( /* translators: %s: Hit rate percentage */ __( '%s%%' ), @@ -514,18 +506,6 @@ private static function get_wp_server(): array { ), 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], ); - - $fields['opcache_cached_scripts'] = array( - 'label' => __( 'OPcache cached scripts' ), - 'value' => number_format_i18n( $opcache_status['opcache_statistics']['num_cached_scripts'] ), - 'debug' => $opcache_status['opcache_statistics']['num_cached_scripts'], - ); - - $fields['opcache_cached_keys'] = array( - 'label' => __( 'OPcache cached keys' ), - 'value' => number_format_i18n( $opcache_status['opcache_statistics']['num_cached_keys'] ), - 'debug' => $opcache_status['opcache_statistics']['num_cached_keys'], - ); } } diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 64ef8f25eadf6..d586ef79db965 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2687,55 +2687,49 @@ public function get_test_autoloaded_options() { return $result; } - __( 'OPcache is enabled' ), - 'status' => 'good', - 'badge' => array( - 'label' => __( 'Performance' ), - 'color' => 'blue', - ), - 'description' => sprintf( - '

%s

', - __( 'OPcache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) - ), - 'actions' => sprintf( - '

%s %s

', - 'https://www.php.net/manual/en/book.opcache.php', - __( 'Learn more about OPcache.' ), - /* translators: Hidden accessibility text. */ - __( '(opens in a new tab)' ) - ), - 'test' => 'opcache', - ); + $result = array( + 'label' => __( 'OPcache is enabled' ), + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '

%s

', + __( 'OPcache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) + ), + 'actions' => sprintf( + '

%s %s

', + 'https://www.php.net/manual/en/book.opcache.php', + __( 'Learn more about OPcache.' ), + /* translators: Hidden accessibility text. */ + __( '(opens in a new tab)' ) + ), + 'test' => 'opcache', + ); - if ( $opcache_loaded ) { - $result['status'] = 'recommended'; - $result['label'] = __( 'OPcache is not available' ); - $result['description'] .= '

' . __( 'OPcache is not installed or enabled on your server. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; - } elseif ( ! $opcache_enabled ) { - $result['status'] = 'recommended'; - $result['label'] = __( 'OPcache is installed but not enabled' ); - $result['description'] .= '

' . __( 'OPcache is installed but not enabled. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; - } + if ( ! $opcode_cache_enabled ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'Opcode cache is not enabled' ); + $result['description'] .= '

' . __( 'OPcache is not enabled. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; + } - return $result; -} + return $result; + } /** * Returns a set of tests that belong to the site status page. From 2ef962da82d4556ade90d1b2eca97c75fdd4f11c Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:48:40 +0800 Subject: [PATCH 04/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index d586ef79db965..620e78162af54 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2725,7 +2725,7 @@ public function get_test_opcache() { if ( ! $opcode_cache_enabled ) { $result['status'] = 'recommended'; $result['label'] = __( 'Opcode cache is not enabled' ); - $result['description'] .= '

' . __( 'OPcache is not enabled. Enabling OPcache can significantly improve the performance of your site.' ) . '

'; + $result['description'] .= '

' . __( 'Opcode cache is not enabled. Enabling this cache can significantly improve the performance of your site.' ) . '

'; } return $result; From 620c6872143100cc1b6f5a520ce5f6b0048f3048 Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:48:59 +0800 Subject: [PATCH 05/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 620e78162af54..f71e38977e74f 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2821,7 +2821,7 @@ public static function get_tests() { ), 'opcache' => array( 'label' => __( 'OPcache' ), - 'test' => 'opcache', + 'test' => 'opcode_cache', ), ), 'async' => array( From e35fe8a143b76d9571293ce143b0f37fc080eed4 Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:49:38 +0800 Subject: [PATCH 06/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index f71e38977e74f..257431a2edbdc 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2690,7 +2690,7 @@ public function get_test_autoloaded_options() { /** * Tests if Opcode cache is enabled and available. * - * @since 6.7.0 + * @since 6.9.0 * * @return array The test result. */ From d546cb49d37440cbbb74e4fd7922ed90b703e7ac Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:50:05 +0800 Subject: [PATCH 07/31] Update src/wp-admin/includes/class-wp-debug-data.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 3dbc933707060..5dcffd8d0fad7 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -478,7 +478,7 @@ private static function get_wp_server(): array { if ( $opcache_status ) { $fields['opcache_enabled'] = array( 'label' => __( 'Opcode cache' ), - 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), + 'value' => ( $opcache_status['opcode_cache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), 'debug' => $opcache_status['opcache_enabled'], ); From 1ea330c129c2cec918e281200733bb84c1e5588e Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:50:23 +0800 Subject: [PATCH 08/31] Update src/wp-admin/includes/class-wp-debug-data.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 5dcffd8d0fad7..af4fa15783bea 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -476,7 +476,7 @@ private static function get_wp_server(): array { $opcache_status = opcache_get_status( false ); if ( $opcache_status ) { - $fields['opcache_enabled'] = array( + $fields['opcode_cache'] = array( 'label' => __( 'Opcode cache' ), 'value' => ( $opcache_status['opcode_cache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), 'debug' => $opcache_status['opcache_enabled'], From 232ea6459e87f9005ae4c86e9fe67b4a68632a3a Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:50:41 +0800 Subject: [PATCH 09/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 257431a2edbdc..4409e8ce0c927 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2702,7 +2702,7 @@ public function get_test_opcache() { } $result = array( - 'label' => __( 'OPcache is enabled' ), + 'label' => __( 'Opcode cache is enabled' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Performance' ), From 152e81a99b0c9eec30e87eade7b74b73829dee9d Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:51:00 +0800 Subject: [PATCH 10/31] Update src/wp-admin/includes/class-wp-debug-data.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index af4fa15783bea..d8b27b4b711ab 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -497,7 +497,7 @@ private static function get_wp_server(): array { ), ); - $fields['opcache_hit_rate'] = array( + $fields['opcode_cache_hit_rate'] = array( 'label' => __( 'Opcode cache hit rate' ), 'value' => sprintf( /* translators: %s: Hit rate percentage */ From 63f41ea58f9689fabb409e2e523e0b4c502d8010 Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:51:24 +0800 Subject: [PATCH 11/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 4409e8ce0c927..d45e0bce56043 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2688,7 +2688,7 @@ public function get_test_autoloaded_options() { } /** - * Tests if Opcode cache is enabled and available. + * Tests if opcode cache is enabled and available. * * @since 6.9.0 * From 923db6f8f28b98bce922fb69de93782f7fc55436 Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:51:48 +0800 Subject: [PATCH 12/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index d45e0bce56043..6fb465e05f7e5 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2694,7 +2694,7 @@ public function get_test_autoloaded_options() { * * @return array The test result. */ - public function get_test_opcache() { + public function get_test_opcode_cache() { $opcode_cache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { $status = opcache_get_status( false ); From 801cbee30b730925fbb3e713580f1164c0660e11 Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:52:01 +0800 Subject: [PATCH 13/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 6fb465e05f7e5..56925ee15ad29 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2710,7 +2710,7 @@ public function get_test_opcode_cache() { ), 'description' => sprintf( '

%s

', - __( 'OPcache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) + __( 'Opcode cache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) ), 'actions' => sprintf( '

%s %s

', From 5ad77f963996c6db129fba838b76b8a95016d98f Mon Sep 17 00:00:00 2001 From: "Rolly G. Bueno Jr." <16076280+rollybueno@users.noreply.github.com> Date: Wed, 6 Aug 2025 08:52:46 +0800 Subject: [PATCH 14/31] Apply suggestions from code review Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- src/wp-admin/includes/class-wp-site-health.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index d8b27b4b711ab..b267144fe41c2 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -482,7 +482,7 @@ private static function get_wp_server(): array { 'debug' => $opcache_status['opcache_enabled'], ); - $fields['opcache_memory_usage'] = array( + $fields['opcode_cache_memory_usage'] = array( 'label' => __( 'Opcode cache memory usage' ), 'value' => sprintf( /* translators: 1: Used memory, 2: Total memory */ diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 56925ee15ad29..bd9e9523d0a31 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2819,8 +2819,8 @@ public static function get_tests() { 'label' => __( 'Autoloaded options' ), 'test' => 'autoloaded_options', ), - 'opcache' => array( - 'label' => __( 'OPcache' ), + 'opcode_cache' => array( + 'label' => __( 'Opcode cache' ), 'test' => 'opcode_cache', ), ), From 3fd57b9eda3eb16edd7c8f42dd313b866ecfe53a Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Wed, 6 Aug 2025 10:20:41 +0800 Subject: [PATCH 15/31] Site HEalth: Add default opcode item in server when disabled --- src/wp-admin/includes/class-wp-debug-data.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index b267144fe41c2..6c6657412168f 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -478,7 +478,7 @@ private static function get_wp_server(): array { if ( $opcache_status ) { $fields['opcode_cache'] = array( 'label' => __( 'Opcode cache' ), - 'value' => ( $opcache_status['opcode_cache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), + 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), 'debug' => $opcache_status['opcache_enabled'], ); @@ -507,6 +507,12 @@ private static function get_wp_server(): array { 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], ); } + } else { + $fields['opcode_cache'] = array( + 'label' => __( 'Opcode cache' ), + 'value' => __( 'Disabled' ), + 'debug' => 'not available', + ); } // Pretty permalinks. From e62c774bf1d140b2971d4a7d8f229e7ea84750cc Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 19 Aug 2025 19:48:24 +0800 Subject: [PATCH 16/31] Feedback: Silence call but add new logic to compensate --- src/wp-admin/includes/class-wp-debug-data.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 6c6657412168f..65df77068bc29 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -473,9 +473,15 @@ private static function get_wp_server(): array { // Opcode Cache. if ( function_exists( 'opcache_get_status' ) ) { - $opcache_status = opcache_get_status( false ); + $opcache_status = @opcache_get_status( false ); - if ( $opcache_status ) { + if ( false === $opcache_status ) { + $fields['opcode_cache'] = array( + 'label' => __( 'Opcode cache' ), + 'value' => __( 'Disabled by configuration' ), + 'debug' => 'not available', + ); + } else { $fields['opcode_cache'] = array( 'label' => __( 'Opcode cache' ), 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), From 4a39b006b1a337f1e770dd6622909e923bc34a0c Mon Sep 17 00:00:00 2001 From: Rolly Bueno <16076280+rollybueno@users.noreply.github.com> Date: Wed, 21 Jan 2026 06:59:41 +0800 Subject: [PATCH 17/31] Apply suggestions from code review Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- src/wp-admin/includes/class-wp-site-health.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 7a059d5419aef..1ecd76ea5928f 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -473,7 +473,7 @@ private static function get_wp_server(): array { // Opcode Cache. if ( function_exists( 'opcache_get_status' ) ) { - $opcache_status = @opcache_get_status( false ); + $opcache_status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. if ( false === $opcache_status ) { $fields['opcode_cache'] = array( diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 9918efc5398e1..2d39bf8719bc8 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2758,7 +2758,7 @@ public function get_test_search_engine_visibility() { /** * Tests if opcode cache is enabled and available. * - * @since 6.9.0 + * @since 7.0.0 * * @return array The test result. */ From c3ef929e2d212dc77c40ab4664d6a37f4327ad43 Mon Sep 17 00:00:00 2001 From: Rolly Bueno <16076280+rollybueno@users.noreply.github.com> Date: Wed, 21 Jan 2026 07:23:30 +0800 Subject: [PATCH 18/31] Update src/wp-admin/includes/class-wp-site-health.php Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 2d39bf8719bc8..6af131a7fc3b0 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2787,7 +2787,7 @@ public function get_test_opcode_cache() { /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ), - 'test' => 'opcache', + 'test' => 'opcache_cache', ); if ( ! $opcode_cache_enabled ) { From b8ee6437163149405182e8436f6328f8c0256075 Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Wed, 21 Jan 2026 07:58:54 +0800 Subject: [PATCH 19/31] Improvement: Conditionally display additional info based on 'opcache_enabled' value --- src/wp-admin/includes/class-wp-debug-data.php | 48 ++++++++++--------- .../includes/class-wp-site-health.php | 20 ++++---- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 1ecd76ea5928f..ac4963f63e528 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -488,30 +488,32 @@ private static function get_wp_server(): array { 'debug' => $opcache_status['opcache_enabled'], ); - $fields['opcode_cache_memory_usage'] = array( - 'label' => __( 'Opcode cache memory usage' ), - 'value' => sprintf( - /* translators: 1: Used memory, 2: Total memory */ - __( '%1$s of %2$s' ), - size_format( $opcache_status['memory_usage']['used_memory'] ), - size_format( $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] ) - ), - 'debug' => sprintf( - '%s of %s', - $opcache_status['memory_usage']['used_memory'], - $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] - ), - ); + if ( true === $opcache_status['opcache_enabled'] ) { + $fields['opcode_cache_memory_usage'] = array( + 'label' => __( 'Opcode cache memory usage' ), + 'value' => sprintf( + /* translators: 1: Used memory, 2: Total memory */ + __( '%1$s of %2$s' ), + size_format( $opcache_status['memory_usage']['used_memory'] ), + size_format( $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] ) + ), + 'debug' => sprintf( + '%s of %s', + $opcache_status['memory_usage']['used_memory'], + $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] + ), + ); - $fields['opcode_cache_hit_rate'] = array( - 'label' => __( 'Opcode cache hit rate' ), - 'value' => sprintf( - /* translators: %s: Hit rate percentage */ - __( '%s%%' ), - round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) - ), - 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], - ); + $fields['opcode_cache_hit_rate'] = array( + 'label' => __( 'Opcode cache hit rate' ), + 'value' => sprintf( + /* translators: %s: Hit rate percentage */ + __( '%s%%' ), + round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) + ), + 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], + ); + } } } else { $fields['opcode_cache'] = array( diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 6af131a7fc3b0..88e69a20a54dd 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2765,8 +2765,12 @@ public function get_test_search_engine_visibility() { public function get_test_opcode_cache() { $opcode_cache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { - $status = opcache_get_status( false ); - $opcode_cache_enabled = $status['opcache_enabled']; + $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. + if ( $status ) { + if( true === $status['opcache_enabled'] ) { + $opcode_cache_enabled = true; + } + } } $result = array( @@ -3463,14 +3467,14 @@ public function get_page_cache_headers() { 'x-srcache-fetch-status' => $cache_hit_callback, // Generic caching proxies (Nginx, Varnish, etc.) - 'x-cache' => $cache_hit_callback, - 'x-cache-status' => $cache_hit_callback, - 'x-litespeed-cache' => $cache_hit_callback, - 'x-proxy-cache' => $cache_hit_callback, - 'via' => '', + 'x-cache' => $cache_hit_callback, + 'x-cache-status' => $cache_hit_callback, + 'x-litespeed-cache' => $cache_hit_callback, + 'x-proxy-cache' => $cache_hit_callback, + 'via' => '', // Cloudflare - 'cf-cache-status' => $cache_hit_callback, + 'cf-cache-status' => $cache_hit_callback, ); /** From dd325c431f0e3ea5f8a7d2f19d9736fccf54212c Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Wed, 21 Jan 2026 07:59:28 +0800 Subject: [PATCH 20/31] Fix: Coding standard --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 88e69a20a54dd..68cfdb18cabf1 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2767,7 +2767,7 @@ public function get_test_opcode_cache() { if ( function_exists( 'opcache_get_status' ) ) { $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. if ( $status ) { - if( true === $status['opcache_enabled'] ) { + if ( true === $status['opcache_enabled'] ) { $opcode_cache_enabled = true; } } From 0dae7c5ed24befe350e6af517ae68228ca4995c8 Mon Sep 17 00:00:00 2001 From: Rolly Bueno <16076280+rollybueno@users.noreply.github.com> Date: Wed, 21 Jan 2026 08:13:24 +0800 Subject: [PATCH 21/31] Apply suggestions from code review Co-authored-by: Weston Ruter --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- src/wp-admin/includes/class-wp-site-health.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index ac4963f63e528..55bf6449e8dad 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -484,7 +484,7 @@ private static function get_wp_server(): array { } else { $fields['opcode_cache'] = array( 'label' => __( 'Opcode cache' ), - 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), + 'value' => $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ), 'debug' => $opcache_status['opcache_enabled'], ); diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 68cfdb18cabf1..c2318824ff996 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2766,10 +2766,8 @@ public function get_test_opcode_cache() { $opcode_cache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. - if ( $status ) { - if ( true === $status['opcache_enabled'] ) { - $opcode_cache_enabled = true; - } + if ( $status && true === $status['opcache_enabled'] ) { + $opcode_cache_enabled = true; } } From 17e5a798ca2acdee872ea70398983bab9419f65b Mon Sep 17 00:00:00 2001 From: Rolly Bueno <16076280+rollybueno@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:33:22 +0800 Subject: [PATCH 22/31] Apply suggestions from code review Co-authored-by: Weston Ruter Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- src/wp-admin/includes/class-wp-site-health.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 55bf6449e8dad..e66b9535625e6 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -473,7 +473,7 @@ private static function get_wp_server(): array { // Opcode Cache. if ( function_exists( 'opcache_get_status' ) ) { - $opcache_status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. + $opcache_status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in failure case. if ( false === $opcache_status ) { $fields['opcode_cache'] = array( diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index c2318824ff996..abc9298050d29 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2760,7 +2760,7 @@ public function get_test_search_engine_visibility() { * * @since 7.0.0 * - * @return array The test result. + * @return array> The test result. */ public function get_test_opcode_cache() { $opcode_cache_enabled = false; @@ -2795,7 +2795,7 @@ public function get_test_opcode_cache() { if ( ! $opcode_cache_enabled ) { $result['status'] = 'recommended'; $result['label'] = __( 'Opcode cache is not enabled' ); - $result['description'] .= '

' . __( 'Opcode cache is not enabled. Enabling this cache can significantly improve the performance of your site.' ) . '

'; + $result['description'] .= '

' . __( 'Enabling this cache can significantly improve the performance of your site.' ) . '

'; } return $result; From 1e6815b1798eec791de6b344e9fb2cb0a3d8d341 Mon Sep 17 00:00:00 2001 From: Rolly Bueno <16076280+rollybueno@users.noreply.github.com> Date: Tue, 27 Jan 2026 08:53:07 +0800 Subject: [PATCH 23/31] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/wp-admin/includes/class-wp-site-health.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index abc9298050d29..4e35d3a8b020b 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2784,12 +2784,12 @@ public function get_test_opcode_cache() { ), 'actions' => sprintf( '

%s %s

', - 'https://www.php.net/manual/en/book.opcache.php', + esc_url( 'https://www.php.net/manual/en/book.opcache.php' ), __( 'Learn more about OPcache.' ), /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ), - 'test' => 'opcache_cache', + 'test' => 'opcode_cache', ); if ( ! $opcode_cache_enabled ) { From cb952315faf54cb99505e5e7986f39434d362fed Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 3 Feb 2026 08:18:37 +0800 Subject: [PATCH 24/31] Test Unit: Add tests for resturn structure, enabled or disabled --- tests/phpunit/tests/admin/wpSiteHealth.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 0c6a42f71bea3..55e1cbe5e27f7 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -572,4 +572,59 @@ public static function set_autoloaded_option( $bytes = 800000 ) { // Force autoloading so that WordPress core does not override it. See https://core.trac.wordpress.org/changeset/57920. add_option( 'test_set_autoloaded_option', $heavy_option_string, '', true ); } + + /** + * Tests get_test_opcode_cache() return structure. + * + * @covers ::get_test_opcode_cache() + */ + public function test_get_test_opcode_cache_return_structure() { + $result = $this->instance->get_test_opcode_cache(); + + $this->assertIsArray( $result ); + $this->assertArrayHasKey( 'label', $result ); + $this->assertArrayHasKey( 'status', $result ); + $this->assertArrayHasKey( 'badge', $result ); + $this->assertArrayHasKey( 'description', $result ); + $this->assertArrayHasKey( 'actions', $result ); + $this->assertArrayHasKey( 'test', $result ); + + $this->assertSame( 'opcode_cache', $result['test'] ); + $this->assertSame( + array( + 'label' => __( 'Performance' ), + 'color' => 'blue', + ), + $result['badge'] + ); + $this->assertContains( $result['status'], array( 'good', 'recommended' ), 'Status must be good or recommended.' ); + } + + /** + * Tests get_test_opcode_cache() result when opcode cache is enabled or not. + * + * Covers: opcache enabled, disabled, not available, and opcache_get_status() returns false. + * + * @covers ::get_test_opcode_cache() + */ + public function test_get_test_opcode_cache_result_by_environment() { + $result = $this->instance->get_test_opcode_cache(); + + $opcache_enabled = false; + if ( function_exists( 'opcache_get_status' ) ) { + $status = @opcache_get_status( false ); + if ( $status && true === $status['opcache_enabled'] ) { + $opcache_enabled = true; + } + } + + if ( $opcache_enabled ) { + $this->assertSame( 'good', $result['status'], 'When opcache is enabled, status should be "good".' ); + $this->assertSame( __( 'Opcode cache is enabled' ), $result['label'] ); + } else { + $this->assertSame( 'recommended', $result['status'] ); + $this->assertSame( __( 'Opcode cache is not enabled' ), $result['label'] ); + $this->assertStringContainsString( __( 'Enabling this cache can significantly improve the performance of your site.' ), $result['description'] ); + } + } } From 8b1d774ec465d0d48a45160de2f4a6cccee5e99f Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 3 Feb 2026 08:39:37 +0800 Subject: [PATCH 25/31] Test Unit: Ignore silent call --- tests/phpunit/tests/admin/wpSiteHealth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 55e1cbe5e27f7..0c4bc840b42a6 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -612,7 +612,7 @@ public function test_get_test_opcode_cache_result_by_environment() { $opcache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { - $status = @opcache_get_status( false ); + $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. if ( $status && true === $status['opcache_enabled'] ) { $opcache_enabled = true; } From 6cd176b80b3cb93747f6cbfc7b802ab6adade8ea Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 10 Feb 2026 10:14:30 +0800 Subject: [PATCH 26/31] Remove warning emission on test unit This seems way more restrictive than the actual function code --- tests/phpunit/tests/admin/wpSiteHealth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 0c4bc840b42a6..2d511989382d9 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -612,7 +612,7 @@ public function test_get_test_opcode_cache_result_by_environment() { $opcache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { - $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. + $status = opcache_get_status( false ); if ( $status && true === $status['opcache_enabled'] ) { $opcache_enabled = true; } From 2c7dee10e427ec25157fb86a1c45419e00e48582 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 10 Feb 2026 09:07:23 -0800 Subject: [PATCH 27/31] Add ticket references --- tests/phpunit/tests/admin/wpSiteHealth.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index bdbeaad1f771f..d012177d60097 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -576,6 +576,8 @@ public static function set_autoloaded_option( $bytes = 800000 ) { /** * Tests get_test_opcode_cache() return structure. * + * @ticket 63697 + * * @covers ::get_test_opcode_cache() */ public function test_get_test_opcode_cache_return_structure() { @@ -605,6 +607,8 @@ public function test_get_test_opcode_cache_return_structure() { * * Covers: opcache enabled, disabled, not available, and opcache_get_status() returns false. * + * @ticket 63697 + * * @covers ::get_test_opcode_cache() */ public function test_get_test_opcode_cache_result_by_environment() { From 6ef53dee3d782442b8ef9e1b4bc21cffd4a61816 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 10 Feb 2026 09:11:05 -0800 Subject: [PATCH 28/31] Fix phpcs:ignore --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 4e35d3a8b020b..8b96e4a09a539 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2765,7 +2765,7 @@ public function get_test_search_engine_visibility() { public function get_test_opcode_cache() { $opcode_cache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { - $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discourage -- Warning emitted in failure case. + $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in failure case. if ( $status && true === $status['opcache_enabled'] ) { $opcode_cache_enabled = true; } From a282d58790c0daa5bc5ee0f6941447bfe40abd50 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 11 Feb 2026 10:26:05 -0800 Subject: [PATCH 29/31] Add cache full status and interned strings usage to Opcode Cache debug information. Expanded the Opcode Cache debug data to include: - 'opcode_cache_full': Indicates if the cache has reached its capacity. - 'opcode_cache_interned_strings_usage': Displays the percentage of the interned strings buffer used, the total buffer size, and the amount of free memory. These additions provide more comprehensive diagnostic information for troubleshooting performance issues related to PHP's OPcache. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: szepeviktor --- src/wp-admin/includes/class-wp-debug-data.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index dde79e817a5c4..df8f0cb0809cc 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -504,6 +504,23 @@ private static function get_wp_server(): array { ), ); + $fields['opcode_cache_interned_strings_usage'] = array( + 'label' => __( 'Opcode cache interned strings usage' ), + 'value' => sprintf( + /* translators: 1: Percentage used, 2: Total memory, 3: Free memory */ + __( '%1$s%% of %2$s (%3$s free)' ), + number_format_i18n( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), + size_format( $opcache_status['interned_strings_usage']['buffer_size'] ), + size_format( $opcache_status['interned_strings_usage']['free_memory'] ) + ), + 'debug' => sprintf( + '%s%% of %s (%s free)', + round( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), + $opcache_status['interned_strings_usage']['buffer_size'], + $opcache_status['interned_strings_usage']['free_memory'] + ), + ); + $fields['opcode_cache_hit_rate'] = array( 'label' => __( 'Opcode cache hit rate' ), 'value' => sprintf( @@ -513,6 +530,12 @@ private static function get_wp_server(): array { ), 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], ); + + $fields['opcode_cache_full'] = array( + 'label' => __( 'Is the Opcode cache full?' ), + 'value' => $opcache_status['cache_full'] ? __( 'Yes' ) : __( 'No' ), + 'debug' => $opcache_status['cache_full'], + ); } } } else { From 8eaebf3f873778b5c4d3ebfa45f9bc7b5b98b940 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 11 Feb 2026 10:58:28 -0800 Subject: [PATCH 30/31] Add missing return type hint --- src/wp-admin/includes/class-wp-site-health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 8b96e4a09a539..93a45f56236c3 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2762,7 +2762,7 @@ public function get_test_search_engine_visibility() { * * @return array> The test result. */ - public function get_test_opcode_cache() { + public function get_test_opcode_cache(): array { $opcode_cache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in failure case. From 57dcb5a29eba1b9f77ffce12c4f56d75a6ebc4f7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 11 Feb 2026 11:47:23 -0800 Subject: [PATCH 31/31] Improve robustness and localization of Opcode Cache debug information. - Prevent division by zero in `WP_Debug_Data` when the interned strings buffer is empty. - Ensure the Opcode Cache hit rate is correctly localized using `number_format_i18n()`. - Silence `opcache_get_status()` in PHPUnit tests to prevent warnings in restricted environments, maintaining consistency with core code. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/wp-admin/includes/class-wp-debug-data.php | 38 ++++++++++--------- tests/phpunit/tests/admin/wpSiteHealth.php | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index df8f0cb0809cc..98927f94e68fd 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -504,31 +504,33 @@ private static function get_wp_server(): array { ), ); - $fields['opcode_cache_interned_strings_usage'] = array( - 'label' => __( 'Opcode cache interned strings usage' ), - 'value' => sprintf( - /* translators: 1: Percentage used, 2: Total memory, 3: Free memory */ - __( '%1$s%% of %2$s (%3$s free)' ), - number_format_i18n( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), - size_format( $opcache_status['interned_strings_usage']['buffer_size'] ), - size_format( $opcache_status['interned_strings_usage']['free_memory'] ) - ), - 'debug' => sprintf( - '%s%% of %s (%s free)', - round( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), - $opcache_status['interned_strings_usage']['buffer_size'], - $opcache_status['interned_strings_usage']['free_memory'] - ), - ); + if ( 0 !== $opcache_status['interned_strings_usage']['buffer_size'] ) { + $fields['opcode_cache_interned_strings_usage'] = array( + 'label' => __( 'Opcode cache interned strings usage' ), + 'value' => sprintf( + /* translators: 1: Percentage used, 2: Total memory, 3: Free memory */ + __( '%1$s%% of %2$s (%3$s free)' ), + number_format_i18n( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), + size_format( $opcache_status['interned_strings_usage']['buffer_size'] ), + size_format( $opcache_status['interned_strings_usage']['free_memory'] ) + ), + 'debug' => sprintf( + '%s%% of %s (%s free)', + round( ( $opcache_status['interned_strings_usage']['used_memory'] / $opcache_status['interned_strings_usage']['buffer_size'] ) * 100, 2 ), + $opcache_status['interned_strings_usage']['buffer_size'], + $opcache_status['interned_strings_usage']['free_memory'] + ), + ); + } $fields['opcode_cache_hit_rate'] = array( 'label' => __( 'Opcode cache hit rate' ), 'value' => sprintf( /* translators: %s: Hit rate percentage */ __( '%s%%' ), - round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) + number_format_i18n( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) ), - 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], + 'debug' => round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ), ); $fields['opcode_cache_full'] = array( diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index d012177d60097..12b563cdfe41f 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -616,7 +616,7 @@ public function test_get_test_opcode_cache_result_by_environment() { $opcache_enabled = false; if ( function_exists( 'opcache_get_status' ) ) { - $status = opcache_get_status( false ); + $status = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in failure case. if ( $status && true === $status['opcache_enabled'] ) { $opcache_enabled = true; }