Plugin overwrites existing (third party) /wp-content/object-cache.php
-
Hi – love the plugin but have run into an issue.
We use Redis Object Cache Pro (https://objectcache.pro/) as an MU plugin. (it’s part of the included features in our Cloudway server package).The WordPress Performance plugin keeps overwriting Object Cache Pro’s object-cache.php file in /wp-content breaking Object Cache Pro’s functionality.
Is there anyway to fix this behaviour, or alternatively, to disable the Object Cache module functionality of the Performance plugin?
The Performance plugin appeared to recognise that there is anObject Cache already present (‘Full Page Cache Health Check is already part of your WordPress version and therefore cannot be loaded as part of the plugin.’) but still keeps overwriting object-cache.php.
Many thanks
-
//EDIT: I might have found a way around it for now.
I noticed the Performance Lab plugin, within load.php, there is a function
perflab_maybe_set_object_cache_dropin()
added by an action. This function appears to rename (backup) the existing object-cache.php file and replaces it with it’s own, which Redis Object Cache Pro doesn’t like.Removing the action that runs perflab_maybe_set_object_cache_dropin() function seems to be a work-around for now, but not sure of any consequences?
I added
remove_action( 'admin_init', 'perflab_maybe_set_object_cache_dropin' );
in my theme’s functions.php to do this.Further update:
Just found the
PERFLAB_DISABLE_OBJECT_CACHE_DROPIN
constant.Setting
define( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN', true );
in wp-config.php seems to do the trick and stops Performance Lab replacing object-cache.phpBetter than removing the action as in post above?
Thanks
Hi @tictok,
Thanks for reaching out. We are aware of possible conflicts as you’ve described, although these were depending on the order of how a plugin generated their object-cache.php file.
While we’ve since made changes to account for other possible ways third party plugins handle existing object-cache.php files, I’d need to check this with the team to see if we’re missing anything. I’ll also check on the best use of PERFLAB_DISABLE_OBJECT_CACHE_DROPIN.
While I’m doing so, can you check and see if there is an
object-cache-plst-orig.php
file existing in the same directory, which may reference or match the contents of your Redis Object Cache Pro generated object cCache file? I ask as this is the expected behavior when a conflict is determined, with more details on this within this comment.HI – thanks or getting back to me.
To answer your query, yes, the
object-cache-plst-orig.php
backup file is created.The order the plugins are activated in doesn’t appear to make any difference. The object-cache.php file that Object Cache Pro creates always gets overwritten by the performance plugin, resulting in Object Cache Pro reporting an Invalid drop-in file.
In case it’s of any help…
Contents of Performance plugins
object-cache.php
:<?php /** * Object cache drop-in from Performance Lab plugin. * * This drop-in is used, admittedly as a hack, to be able to measure server * timings in WordPress as early as possible. Once a plugin is loaded, it is * too late to capture several critical events. * * This file respects any real object cache implementation the site may already * be using, and it is implemented in a way that there is no risk for breakage. * * If you do not want the Performance Lab plugin to place this file and thus be * limited to server timings only from after plugins are loaded, you can remove * this file and set the following constant (e.g. in wp-config.php): * * define( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN', true ); * * @package performance-lab * @since 1.8.0 */ // Set constant to be able to later check for whether this file was loaded. define( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION', 1 ); /** * Loads the Performance Lab Server-Timing API if available. * * This function will short-circuit if the constant * 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true. * * @since 1.8.0 */ function perflab_load_server_timing_api_from_dropin() { if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) { return; } $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; $plugin_dir = $plugins_dir . '/performance-lab/'; if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) { $plugin_dir = $plugins_dir . '/performance/'; if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) { return; } } require_once $plugin_dir . 'server-timing/class-perflab-server-timing-metric.php'; require_once $plugin_dir . 'server-timing/class-perflab-server-timing.php'; require_once $plugin_dir . 'server-timing/load.php'; require_once $plugin_dir . 'server-timing/defaults.php'; } perflab_load_server_timing_api_from_dropin(); // Load the original object cache drop-in if present. if ( file_exists( WP_CONTENT_DIR . '/object-cache-plst-orig.php' ) ) { require_once WP_CONTENT_DIR . '/object-cache-plst-orig.php'; }
Contents of
object-cache-plst-orig.php
(backup of object cache pro’s file):<?php /* * Plugin Name: Object Cache Pro (Drop-in) * Plugin URI: https://objectcache.pro * Description: A business class Redis object cache backend for WordPress. * Version: 1.17.0 * Author: Rhubarb Group * Author URI: https://rhubarb.group * License: Proprietary * Requires PHP: 7.2 */ defined('ABSPATH') || exit; if (version_compare(PHP_VERSION, '7.2', '<')) { return require_once ABSPATH . WPINC . '/cache.php'; } if (defined('WP_REDIS_DISABLED') && WP_REDIS_DISABLED) { return; } if (! empty(getenv('WP_REDIS_DISABLED'))) { return; } foreach ([ defined('WP_REDIS_DIR') ? WP_REDIS_DIR : null, // Redis Cache Pro defined('WPMU_PLUGIN_DIR') ? WPMU_PLUGIN_DIR . '/redis-cache-pro' : null, defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR . '/mu-plugins/redis-cache-pro' : null, defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR . '/redis-cache-pro' : null, defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR . '/plugins/redis-cache-pro' : null, // Object Cache Pro defined('WPMU_PLUGIN_DIR') ? WPMU_PLUGIN_DIR . '/object-cache-pro' : null, defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR . '/mu-plugins/object-cache-pro' : null, defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR . '/object-cache-pro' : null, defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR . '/plugins/object-cache-pro' : null, ] as $path) { if ($path === null || ! is_readable("{$path}/api.php")) { continue; } if (include_once "{$path}/api.php") { return; } } error_log('objectcache.critical: Failed to locate and load object cache API'); $GLOBALS['wp_object_cache_errors'] = ['Failed to locate and load object cache API']; if (defined('WP_DEBUG') && WP_DEBUG) { throw new RuntimeException('Failed to locate and load object cache API'); }
For what it’s worth, I’ve been using
define( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN', true );
?in wp-config.php for ac couple of days now.object-cache.php
not overwritten andobject-cache-plst-orig.php
not created. I realise I’ll likely be missing some server timing reporting in WooCommerce status due to this.Off to checkout the the links you’ve shared…
Many thanks
Thanks for sharing an update @tictok, and including the contents of both caching files, very useful. Based on what you’ve shared, what you’re experiencing is expected behavior. If you check the bottom of the object-cache.php file (generated by the Performance Lab plugin), you’ll notice the an
object-cache-plst-orig.php
file is requested. This is the Redis Cache Proobject-cache.php
file, only renamed and requested from within the Performance Labobject-cache.php
file. We do this to ensure compatibility with third party plugins. While I haven’t checked the Redic Cache Pro plugin it may be a case that the invalid drop-in file being reported can be disregarded. I will see if I can check this with one of my test environments.In relation to PERFLAB_DISABLE_OBJECT_CACHE_DROPIN I checked this with the team and you’re correct. This will result in the Performance Lab plugin not inserting it’s own object-cache.php file.
Hey James – many thanks for the info. All makes sense.
This led me to investigate the Object Cache Pro plugin a little further.
It appears to have a strict check (using
get_plugin_data()
) to see if the metadata at the top of the object-cache.php file matches what it expects (checking against it’s own copy of the file). Therefore, unfortunately, despite the include/require at the bottom of your plugin’s object-cache.php (which I guess would work in the majority of scenarios), the metadata at the top of your object-cache.php doesn’t match, causing Redis object cache Pro to flag the object-cache.php as invalid and disables itself.Suspect you will consider this as an edge-case, but thought I’d share anyway.
Many thanks.
Many thanks for the update, and sharing your findings after checking how Redis Pro works with existing object-cache files. While I didn’t get a chance to check Redis Pro at this point, I see there is a GitHub issue open with regards the overwriting the object-cache file.
While I’ll hopefully get time to check Redis Pro, when you mention it determines the Performance Lab object-cache.php file as invalid and disables itself, can you share whether it suggests replacing this file, or does it disable any feature of Redis Pro?
Hiya James
When Redis Object Cache Pro (https://objectcache.pro) detects that object-cache.php is not it’s own, the cache is disabled and the drop-in (object-cache.php) reported as invalid. It doesn’t suggest replacing object-cache.php.
However, there is a button to enable the object cache again.
Screenshot: https://snipboard.io/fjVKcY.jpg
Clicking this replaces object-cache.php with its own version of the file, and the drop-in is temporarily reported as being Valid again.
Unfortunately, it looks like the Performance plugin quickly replaces the object-cache.php file with it’s own again –?once again disabling the cache and reporting as invalid.
FYI, the other options and feature of the Redis Cache Pro plugin are also disabled… it’s not just a visual indicator.
Hope that helps, but do let me know if I can share any more info
Thanks
Many thanks for the update @tictok. Based on your experience I’ve created a GitHub issue to review how the plugin handles such conflicts.
If you want to also subscribe to #628 this issue, which was opened by a Redit Pro developer, will introduce a filter to help resolve the issue you’re facing.
I’ll close this support topic now, however, feel free to chime in on to the above on GitHub. Thanks again for raising this.
W3 Total cache says same issue: The Object Cache add-in file object-cache.php is not a W3 Total Cache drop-in. Remove it or disable Object Caching.?
Can I use define( ‘PERFLAB_DISABLE_OBJECT_CACHE_DROPIN’, true ); to disable the object-cache.php file? I only use the webp function of Performance Lab.
@luislu Yes, the?
PERFLAB_DISABLE_OBJECT_CACHE_DROPIN
?constant can be used to?disable the object-cache.php?file overwriting. It will need to be set in the wp-config.php file.
- The topic ‘Plugin overwrites existing (third party) /wp-content/object-cache.php’ is closed to new replies.