Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Site Health test for Object Caching #1301

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/performance-lab/includes/site-health/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
// AVIF Support site health check.
require_once __DIR__ . '/avif-support/helper.php';
require_once __DIR__ . '/avif-support/hooks.php';

// Object Cache Support site health info.
require_once __DIR__ . '/object-cache/helper.php';
require_once __DIR__ . '/object-cache/hooks.php';
119 changes: 119 additions & 0 deletions plugins/performance-lab/includes/site-health/object-cache/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* Helper functions used for Object Cache Support Info.
*
* @package performance-lab
* @since 2.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 2.1.0
* @since n.e.x.t

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Callback for Object Cache Info fields.
*
* @return array Fields.
* @since 3.3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 3.3.0
* @since n.e.x.t

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
function object_cache_supported_fields() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function needs the Performance Lab prefix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return array(
'extension' => array(
'label' => __( 'Extension', 'performance-lab' ),
'value' => wp_get_cache_type(),
),
'multiple_gets' => array(
'label' => __( 'Multiple gets', 'performance-lab' ),
'value' => wp_cache_supports( 'get_multiple' ) ? 'Enabled' : 'Disabled',
),
'multiple_sets' => array(
'label' => __( 'Multiple sets', 'performance-lab' ),
'value' => wp_cache_supports( 'set_multiple' ) ? 'Enabled' : 'Disabled',
),
'multiple_deletes' => array(
'label' => __( 'Multiple deletes', 'performance-lab' ),
'value' => wp_cache_supports( 'delete_multiple' ) ? 'Enabled' : 'Disabled',
),
'flush_group' => array(
'label' => __( 'Flush group', 'performance-lab' ),
'value' => wp_cache_supports( 'flush_group' ) ? 'Enabled' : 'Disabled',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't Enabled and Disabled be translated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

),
);
}

/**
* Attempts to determine which object cache is being used.
*
* Note that the guesses made by this function are based on the WP_Object_Cache classes
* that define the 3rd party object cache extension. Changes to those classes could render
* problems with this function's ability to determine which object cache is being used.
*
westonruter marked this conversation as resolved.
Show resolved Hide resolved
* @return string
* @since 3.3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 3.3.0
* @since n.e.x.t

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
function wp_get_cache_type() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a Performance Lab prefix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

global $_wp_using_ext_object_cache, $wp_object_cache;
westonruter marked this conversation as resolved.
Show resolved Hide resolved

if ( ! empty( $_wp_using_ext_object_cache ) ) {
// Test for Memcached PECL extension memcached object cache (https://github.com/tollmanz/wordpress-memcached-backend)
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not using namespaces, the \ an be removed.

Suggested change
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) {
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof Memcached ) {

$message = 'Memcached';

// Test for Memcache PECL extension memcached object cache (https://wordpress.org/extend/plugins/memcached/)
} elseif ( isset( $wp_object_cache->mc ) ) {
$is_memcache = true;
foreach ( $wp_object_cache->mc as $bucket ) {
if ( ! $bucket instanceof \Memcache && ! $bucket instanceof \Memcached ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( ! $bucket instanceof \Memcache && ! $bucket instanceof \Memcached ) {
if ( ! $bucket instanceof Memcache && ! $bucket instanceof Memcached ) {

$is_memcache = false;
}
}

if ( $is_memcache ) {
$message = 'Memcache';
}

// Test for Xcache object cache (https://plugins.svn.wordpress.org/xcache/trunk/object-cache.php)
} elseif ( $wp_object_cache instanceof \XCache_Object_Cache ) {
$message = 'Xcache';

// Test for WinCache object cache (https://wordpress.org/extend/plugins/wincache-object-cache-backend/)
} elseif ( class_exists( 'WinCache_Object_Cache' ) ) {
$message = 'WinCache';

// Test for APC object cache (https://wordpress.org/extend/plugins/apc/)
} elseif ( class_exists( 'APC_Object_Cache' ) ) {
$message = 'APC';

// Test for WP Redis (https://wordpress.org/plugins/wp-redis/)
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof \Redis ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof \Redis ) {
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof Redis ) {

$message = 'Redis';

// Test for Redis Object Cache (https://wordpress.org/plugins/redis-cache/)
} elseif ( method_exists( $wp_object_cache, 'redis_instance' ) && method_exists( $wp_object_cache,
'redis_status' ) ) {
$message = 'Redis';

// Test for Object Cache Pro (https://objectcache.pro/)
} elseif ( method_exists( $wp_object_cache, 'config' ) && method_exists( $wp_object_cache, 'connection' ) ) {
$message = 'Redis';

// Test for WP LCache Object cache (https://github.com/lcache/wp-lcache)
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \LCache\Integrated ) {
$message = 'WP LCache';

} elseif ( function_exists( 'w3_instance' ) ) {
$config = w3_instance( 'W3_Config' );
$message = 'Unknown';

if ( $config->get_boolean( 'objectcache.enabled' ) ) {
$message = 'W3TC ' . $config->get_string( 'objectcache.engine' );
}
} else {
$message = 'Unknown';
}
} else {
$message = 'Disabled';
}

return $message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Hook callbacks used for Site Health Info.
*
* @package performance-lab
* @since 2.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 2.1.0
* @since n.e.x.t

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Adds Object Cache module to Site Health Info.
*
* @param array $info Site Health Info.
*
* @return array Amended Info.
* @since 3.3.0
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*
* @param array $info Site Health Info.
*
* @return array Amended Info.
* @since 3.3.0
*
*
* @since n.e.x.t
*
* @param array<string, mixed> $info Site Health Info.
* @return array<string, mixed> Amended Info.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
function object_cache_supported_info( array $info ): array {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs Performance Lab prefix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$info['object_cache'] = array(
'label' => __( 'Object Caching', 'performance-lab' ),
'description' => __( 'Shows which features object cache supports and if object caching is in use.',
'performance-lab' ),
'fields' => object_cache_supported_fields(),
);

return $info;
}

add_filter( 'debug_information', 'object_cache_supported_info', 10, 1 );
Loading