-
Notifications
You must be signed in to change notification settings - Fork 382
Detect available object caching and show recommended plugin in admin dashboard. #6493
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
Conversation
Plugin builds for f198357 are ready 🛎️!
|
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.
I made a few comments but I like where this is heading 😄
src/Admin/SiteHealth.php
Outdated
/* | ||
* Try to connect redis server. | ||
*/ | ||
$redis_server = [ |
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.
I see that W3 Total Cache only checks if the Redis
class exists.
Any reason to go further and attempt to ping the Redis server? It seems like a brittle way of determining if there is indeed a Redis server as there may be many things that could cause it not to respond such as a firewall or iptables rule, for instance. It may also come off as hostile to some persons as it's attempting to make a connection that the user did not deliberately agree to.
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.
@pierlon As I understood, We do need to check services with connecting instead of checking if a class of extension exists. And if some services are not able to connect then it's better not to recommend anything.
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.
Right, but attempting to connect and fail would do more harm than good here and is more likely to produce more false positives. We should be only checking if a user's environment is capable of using Redis cache, not if we can connect to a Redis server.
src/Admin/SiteHealth.php
Outdated
*/ | ||
public function is_site_has_memcached() { | ||
|
||
if ( ! ( class_exists( 'Memcache' ) || class_exists( 'Memcached' ) ) ) { |
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.
W3 Total Cache also checks for these ✅
src/Admin/SiteHealth.php
Outdated
return false; | ||
} | ||
|
||
$has_object_cache = false; |
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.
Similar to my comment above, I don't think it our place to attempt to connect to an external service. Checking if the Memcache
or Memcached
class exists seems to be a good enough heuristic measure.
src/Admin/SiteHealth.php
Outdated
$available_cache = $this->check_available_cache(); | ||
|
||
/* translators: plugin recommendation markup */ | ||
$plugin_placeholder = _x( 'We recommend to use %s plugin.', 'plugin recommendation markup', 'amp' ); |
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.
We may want to not recommend any specific plugin, but instead point them to documentation that may guide them how to configure object caching for their site. As mentioned in the issue by @westonruter:
Instead of mentioning the specific plugins in the Site Health info recommendation, the list of backend-specific plugins can be in a documentation page on amp-wp.org. This documentation page can pull together the various pieces of information about object caching spread out across WordPress.org, including:
- https://make.wordpress.org/hosting/handbook/handbook/performance/#object-cache
- https://developer.wordpress.org/reference/classes/wp_object_cache/#persistent-caching
Ultimately, the user should ask their host for the recommended way to enable object caching first before they do it themselves. So our recommendation should be to first contact the host, and then continue with our guidance to try the plugins we've identified which may work with their site.
See support topics about object caching:
- https://wordpress.org/support/topic/how-enable-persistent-object-in-amp-plugin/
- https://wordpress.org/support/topic/amp-error-25/
- https://wordpress.org/support/topic/persistent-object-cache-is-not-enabled-2/
- https://wordpress.org/support/topic/persistent-object-caching-is-not-enabled-2/
- https://wordpress.org/support/topic/persistent-object-cache-is-not-enabled-amp/
Anything we can do to make it easier for users to enable object caching the better.
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.
What about linking off to search results for object caching plugins using a given backend? For example:
- https://wordpress.org/plugins/search/redis+object+cache/
- https://wordpress.org/plugins/search/memcached+object+cache/
- https://wordpress.org/plugins/search/apcu+object+cache/
And then we can include with that a link to our object caching guide so they can see which plugins specifically we've tested: https://amp-wp.org/documentation/getting-started/amp-site-setup/persistent-object-caching/#i-need-help-setting-up-my-persistent-object-cache
At the very lest we can just say: “It looks like you have X available on your server.” where X is the backend service and then they will provide them with a starting point for which plugins to look for.
fd132ed
to
271e75c
Compare
271e75c
to
ceca448
Compare
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.
Apart from attempting to externally connect to Redis and Memcache server instances, this looks OK.
ceca448
to
852a5a4
Compare
…ce/5780-object-cache-guide * 'develop' of github.com:ampproject/amp-wp: (43 commits) Make placeholder dependency on video ID more explicit Fix adding start to placeholder link; improve coverage Let placeholder link point to YouTube permalink and not iframe src Prevent generating closing IMG tags Use coversDefaultClass Remove condition which cannot be reached since video ID is always provided Opt to pass-through iframe for unrecognized YouTube URL rather than convert to link Remove unreachable code Give more explicit array phpdoc type Fix issues identified by phpstan Try installing phpstan via shivammathur/setup-php Try downloading a specific version of phpstan instead of latest Fix yml syntax error Try removing phpstan before composer install Print phpstan version when running on GHA Revert "Revert phpstan ignores" Try adding phpstan version to composer cache key Revert phpstan ignores update unit test cases Sanitize attribute name Use original YouTube URL as placeholder when sanitizing raw embed Fix phpcs alignment warning Use constant instead of member variable Let Document::fromNode() obtain the ownerDocument Deduplicate iframe_props into constant ...
@dhaval-parekh I've made some improvements to the test. It now shows multiple persistent object caching services when they are available and then links to the Add Plugins screen in the admin: Could you please add some test coverage? |
(Without rebasing please 😊) |
Summary
Fixes #5780
Checklist