WP_Site_Health::get_test_opcode_cache(): array<string,

In this article

Tests if opcode cache is enabled and available.

Return

array<string, string|array<string, string>> The test result.

Source

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'] ) {
			$opcode_cache_enabled = true;
		}
	}

	$result = array(
		'label'       => __( 'Opcode cache is enabled' ),
		'status'      => 'good',
		'badge'       => array(
			'label' => __( 'Performance' ),
			'color' => 'blue',
		),
		'description' => sprintf(
			'<p>%s</p>',
			__( '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(
			'<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( 'https://www.php.net/manual/en/book.opcache.php' ),
			__( 'Learn more about OPcache.' ),
			/* translators: Hidden accessibility text. */
			__( '(opens in a new tab)' )
		),
		'test'        => 'opcode_cache',
	);

	if ( ! $opcode_cache_enabled ) {
		$result['status']       = 'recommended';
		$result['label']        = __( 'Opcode cache is not enabled' );
		$result['description'] .= '<p>' . __( 'Enabling this cache can significantly improve the performance of your site.' ) . '</p>';
	}

	return $result;
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.