From d563fb8354f1ad59c902759b11412f9370662c27 Mon Sep 17 00:00:00 2001 From: Khokan Sardar Date: Thu, 20 Aug 2026 22:48:35 +0530 Subject: [PATCH] Site Health: Detect an OPcache file cache as an enabled opcode cache. `opcache_get_status()` reports `opcache_enabled` as false when OPcache runs with `opcache.file_cache_only` enabled, even though the file cache is an active opcode cache. `get_test_opcode_cache()` therefore reported "Opcode cache is not enabled" on those configurations. Treat the `file_cache_only` flag in the status array as an enabled opcode cache. The flag is only present when the file cache is the active backend, so shared memory configurations are unaffected. Fixes #65921. --- src/wp-admin/includes/class-wp-site-health.php | 3 ++- tests/phpunit/tests/admin/wpSiteHealth.php | 3 ++- 2 files changed, 4 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 2ddfaadc4b39d..de0a77fb42c06 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -2802,7 +2802,8 @@ 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. - if ( $status && true === $status['opcache_enabled'] ) { + // OPcache reports `opcache_enabled` as false when only the file cache is in use, though that is still an active opcode cache. + if ( $status && ( true === $status['opcache_enabled'] || ! empty( $status['file_cache_only'] ) ) ) { $opcode_cache_enabled = true; } } diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 6080b477f54c3..5dd1198ec1d09 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -684,6 +684,7 @@ public function test_get_test_opcode_cache_return_structure() { * Covers: opcache enabled, disabled, not available, and opcache_get_status() returns false. * * @ticket 63697 + * @ticket 65921 * * @covers ::get_test_opcode_cache() */ @@ -693,7 +694,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.Discouraged -- Warning emitted in failure case. - if ( $status && true === $status['opcache_enabled'] ) { + if ( $status && ( true === $status['opcache_enabled'] || ! empty( $status['file_cache_only'] ) ) ) { $opcache_enabled = true; } }