• Resolved Rhapsody348

    (@rhapsody348)


    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); // debug

    In 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 mclude

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rhapsody348

    Thank you for reaching out. I am unable to replicate this problem. Can you pleas share the example of the code wrapped with mfunc

    Thanks!

    Thread Starter Rhapsody348

    (@rhapsody348)

    Thanks for the reply Marko. The good news is by changing the Database Cache to APCu it fixed the white screen associated with having to keep the debug mode checked.

    The function below is called to display an icon menu when a mobile device is detected. This is where there is a conflict when Lazy Load images is selected. In the User Experience section if Process HTML Image Tags is unchecked, the white screen does not happen.

    /*************************************
    * function display_icon_menu()
    * This is hooked if a phone display is detected to show
    * Home, Calendar, Roster, Availability, Skipper, Log In/Out Icons
    * 11/18/2020 added popup descriptions for icons
    ************************************/
    
    if (isMobileDevice()) add_action('graphene_navbar_header', 'display_icon_menu');
    
    function display_icon_menu() {
    
    // 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
    }
    
    //$icon_menu = '<span id="parent">
    ' . do_shortcode("[boat]") . ' Home Page
    </span>'; $icon_menu = '<span id="parent">
    ' . do_shortcode("[boat]") . ' Home Page
    </span>'; $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Display Results
    </span>'; $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    View the Calendar
    </span>'; $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Display Crew Roster
    </span>'; // check if skipper, skipper admin or admin logged in and display skipper Edit availability icon, else crew availability icon (check_skipper_admin() || check_skipper() || current_user_can('administrator')) ? $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Skipper Edit Assignments by Event
    </span>' : $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Crew Set Availability
    </span>'; // check if skipper, skipper admin or admin logged in and display skipper icon, else crew assignment icon (check_skipper_admin() || check_skipper() || current_user_can('administrator')) ? $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Display Skipper Menu
    </span>' : $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Crew Check Assignments
    </span>'; // if not logged in display login icon, else logout icon (is_user_logged_in()) ? $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Log Out
    </span>' : $icon_menu .= '&nbsp;|&nbsp;<span id="parent">
    Log In
    </span>'; global $crew_manager_options; if (is_multisite()) $subscription = get_subscription(get_current_blog_id()); if (is_multisite() && (!$subscription && get_current_blog_id()!==1) ) { $icon_menu .= '
    <td><center><b>Subscription Expired - Click here to renew</b></center></td>
    '; // show subscription expired with renewal link } // end if is multisite /*** added below to display banner if emails turned off *****/ $person_logged_in = $skipper_logged_in = $admin_logged_in = false; $current_user = wp_get_current_user(); if ($current_user->ID !== 0) $person_logged_in = true; if ($current_user->ID == (int)$crew_manager_options['skipper'] ) $skipper_logged_in = true; if (check_skipper_admin() ) $skipper_logged_in = true; if (current_user_can('administrator')) $admin_logged_in= true; global $crew_manager_options; if ( (($skipper_logged_in || $admin_logged_in) && (isset($crew_manager_options['stop_crew_email']) && $crew_manager_options['stop_crew_email']==2)) ) { // display banner to skipper that emails are disabled ($subscription) ? $icon_menu .= '' : // show clickable link for email settings update if valid subscription $icon_menu .= '
    <td><center><b>Skipper! - Emails Off in Crew Manger Modify Settings</b></center></td>
    '; // show banner emails disabled } // end if ( ($skipper_logged_in || $admin_logged_in) && $crew_manager_options['stop_crew_email']==2 ) /*** added above to display banner if emails turned off *****/ $icon_menu = '
    ' . $icon_menu. '
    '; // div surround echo $open_notcached . $icon_menu . $close_notcached; // show the icon menu } // end function display_icon_menu()
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rhapsody348

    Thank you for your feedback.

    We’ll investigate this and try to replicate and I’ll get back to you with more informatiuon.

    Thanks!

    Thread Starter Rhapsody348

    (@rhapsody348)

    Marko – it appears that the editor code block on this forum changed the image urls and links from what I pasted. If that is a problem for you to debug, let me know and I’ll post the code using another method.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rhapsody348

    Thank you for your feedback. IS the mfunc comment/code blocks added within the <php> tag?

    Thanks!

    Thread Starter Rhapsody348

    (@rhapsody348)

    Hello Marco,

    I think I understand the question but want to clarify. The mfunc comment / code blocks are added with other text output by the executing PHP code from the plugin. If you mean are separate <?php opening and ?> closing tags added within the text that is output with the mfunc comments then the answer is no. Should I be sending these separate PHP tags before / after code that is inserted between the mfunc tags?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rhapsody348

    The comment/code blocks need to be added after the closing ??> and before any opening <?php tag as shown below. This should not be within any PHP tags and no PHP tahs should be withing te code block

    ?>
    <!-- mfunc mysecurestring -->
    <!-- /mfunc mysecurestring -->
    <?php

    Can you please confirm this?

    Thanks!

    Thread Starter Rhapsody348

    (@rhapsody348)

    Marko – just letting you know I haven’t ignored you. I’ve done some testing but it is taking some time. I’ll need to put this aside until after the holidays and will report back again after the new year. Happy Holidays to you!

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hey @rhapsody348

    No problem. Take as much time as you need.
    Enjoy the holidays!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Found Two Items that Break Page Fragment Caching’ is closed to new replies.