-
Notifications
You must be signed in to change notification settings - Fork 101
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
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
37fe48b
061657f
ec2099d
dd59b4c
d746d31
b2a3c87
74897bb
8f1c0b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||
*/ | ||||||
|
||||||
if ( ! defined( 'ABSPATH' ) ) { | ||||||
exit; // Exit if accessed directly. | ||||||
} | ||||||
|
||||||
/** | ||||||
* Callback for Object Cache Info fields. | ||||||
* | ||||||
* @return array Fields. | ||||||
* @since 3.3.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||
*/ | ||||||
function object_cache_supported_fields() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function needs the Performance Lab prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||
*/ | ||||||
function wp_get_cache_type() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need a Performance Lab prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're not using namespaces, the
Suggested change
|
||||||
$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 ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$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 ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$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 | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
function object_cache_supported_info( array $info ): array { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs Performance Lab prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed