Found Two Items that Break Page Fragment Caching
-
I have been troubleshooting why a white screen appears when I implement Page Fragment Caching on my site. I have a Pro license that I switch between the staging and production site, but I believe the feature I am using is available in the free version. I have isolated two conditions that cause the white screen. These include:
- Lazy Load Images checked and there is an <img tag between the W3TC “mfunc” opening and closing tags
- The Debug Mode Page Cache option is left unchecked on the General Settings page (e.g. you must be in debug mode for it to work)
The testing site used for staging in the site link is where the problem was diagnosed and where testing is being done before moving to the production site. Both are WordPress multisite installations using subdomains. These are installed on the same shared server and have similar settings. I was able to debug the problem by inserting the following lines in the W3TC function _parse_dynamic_mfunc( $matches ) located in file PgCache_ContentGrabber.php to display output before the white screen took over. The debug lines are added immediately after line 1899.
$code = ( $code1 ? $code1 : $code2 );// insert after this line var_dump("
1899
", $code); // debug echo "
Eval: " . eval($code); // debugIn my plugin the function cm_is_w3tc_active() is used to detect if the W3TC plugin is active. This is called where needed to prepare the W3TC opening and closing tags that are used throughout my plugin. These tags surround code for the Page Fragment Cache, and depending on whether the W3TC plugin is detected or not, provides the proper W3TC syntax to open and close the PHP code. The constant W3TC_DYNAMIC_SECURITY is defined in the wp-config.php file.
/************************************************************ * function cm_is_w3tc_active() detects if W3TC Cache plugin * is active either on multisite or standalone sites * Boolean returned true if active, false if not ************************************************************/ function cm_is_w3tc_active() { // stand alone and network activation checked $plugin = 'w3-total-cache/w3-total-cache.php'; // path & filename $w3tc_active = (in_array($plugin, apply_filters('active_plugins', get_option('active_plugins'))) || is_plugin_active_for_network( $plugin ) ); // Boolean true if plugin is activated, else false return $w3tc_active; // make status available }
// only insert W3TC Cache tags if plugin is active $open_notcached = $close_notcached = NULL; if (cm_is_w3tc_active()) { // W3TC Cache Control Tags $open_notcached = '<!-- mfunc ' .W3TC_DYNAMIC_SECURITY. ' echo ''; // opening tag $close_notcached = ''; --> <!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' --> '; // closing tag }
The shared server is Apache running PHP 8.0 and WordPress version 6.1.1. The following W3TC settings are used:
1 – Page Cache: Redis
2 – Database Cache: Redis
3 – Object Cache: APCu
4 – Browser cache: enabled
5 – Lazy Load images: None (works) Enabled – gives white screen
6 – Fragment Cache: Redis
7 – Debug mode: Page Cache Enabled (works) – not checked (gives white screen)
8 – Late initialization: enabled
9 – Late caching: enabled
10 – Minify – enabled with exclusion of mfunc and mcludeThe page I need help with: [log in to see the link]
- The topic ‘Found Two Items that Break Page Fragment Caching’ is closed to new replies.