Support » Plugin: WP Cloudflare Super Page Cache » headers already sent

  • Resolved alx359

    (@alx359)


    Getting the debug.log filled with these:

    PHP Warning: Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 43

    Switched to default theme (2020). Every other plugin disabled but CSPC and WooCommerce.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor Saumya Majumder

    (@isaumya)

    Hi @alx359,
    Yes I am also seeing this error over and over again and not just on line no 43 but on multiple lines.
    Screenshots:
    https://i.imgur.com/ZL3pRxX.png
    https://i.imgur.com/yHydRV8.png

    There are many more pages like these. :/

    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi,
    I have not this problem. Please give me some details in order to replicate it and fix.

    I suggest you to temporary disable the fallback cache or enable the fallback cache via cURL if you want use it, ’cause the error is related to the standard fallback cache mode.

    Plugin Contributor Saumya Majumder

    (@isaumya)

    Hi @salvatorefresta,
    Unfortunately, there is nothing specific that started giving that message on the PHP error log. I also think it is the fallback cache. But the problem is that especially for large high traffic website sit is really hard to turn on cURL as that will show things down very much, I have seen it happening on a big site where I have mistakenly enabled cURL caching.

    I think inside the code you can just add a check if the header has been passed before or not. Also during writing my own plugin I once came across this exact issue and found out that if you are using session_start() without closing the previous session, that also create this same issue. Then I had to stop using PHP session and coded things alternatively to fix that issue. Not sure if that applies here, just sharing my experience.

    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    I know, fallback cache is not a stable feature yet. I will work on it. I hope to replicate the problem.

    If you can, please write the list of active plugins and themes. Maybe there is a conflict with one of these.

    please write the list of active plugins and themes

    Already did:

    default theme (2020). Every other plugin disabled but CSPC and WooCommerce

    EDIT: Mind have reported a separate issue of latest WooCommerce and headers, but it doesn’t seem to directly concern CSPC.

    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    I have a woocommerce active on my test website with a premium theme and some other plugins such like wpml, yasr, litespeed cache, elementor and others.

    I have not any of these errors (of course WP_DEBUG is on true).

    I will try with the default wordpress theme and woocommerce only.

    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi,
    yesterday I tested with @isaumya:

    • twentytwenty + woocommerce + CSPC
    • twentytwenty + woocommerce + CSPC + autoptimize
    • premium theme + woocommerce + CSPC
    • premium theme + woocommerce + CSPC + litespeed cache

    all together and the error is not coming out. Maybe you have some extra newline or space in other PHP files executed before advanced-cache.php such like must-use plugins or wp-config.php.

    Please check it and let me know

    Plugin Contributor Saumya Majumder

    (@isaumya)

    Yes @alx359, Can you please share the list of files you have in mu-plugins/ folder? Check those files. Try the following:

    1. If you have any code inside mu-plugin take then out of that folder. Check your server error log and test to see if you are getting the header errors still.
    2. If not then check the codes inside the PHP files and see if any of them has an extra newline or space at the end of the script. If they have delete those new lines and spaces and test.
    3. If still doesn’t work check if any of the scripts inside mu-plugins have print, echo, printf, vprintf etc. in the code. For more details check: https://stackoverflow.com/a/8028987/2308992

    In short, the problem is not coming from this plugin but somemu-plugin is sending the header before advanced-cache.php can. That’s causing the issue. We have thoroughly tested.

    alx359

    (@alx359)

    Hi Salvatore, Saumya,

    @isaumya:

    Yes I am also seeing this error over and over again and not just on line no 43 but on multiple lines.

    You reported that same issue here. How did you fix it?

    My mu-plugins has only this: health-check-troubleshooting-mode.php which is already std WP. Getting rid of it anyway doesn’t help.

    I still get this stuff filling up my debug.log:

    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 38
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 41
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 42
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 43
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 44
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 45
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 46
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 47
    PHP Warning:  Cannot modify header information - headers already sent in /wp-content/advanced-cache.php on line 48

    @isaumya: I shouldn’t have any Number 2, as tested and reported in the OP:

    Switched to default theme (2020). Every other plugin disabled but CSPC and WooCommerce.

    Any other suggestions?

    Thanks.

    Plugin Contributor Saumya Majumder

    (@isaumya)

    Did you tried taking out the files from the mu plugins folder and test? Also check your wp config files and if you see and blank new lines at the end of that five, remove them. Try and let us know.

    alx359

    (@alx359)

    Okay, did some more tests setting this catcher into advanced-cache.php

    if (headers_sent()) {
    error_log( var_export( headers_list(), true ) );
    }

    and got this:

    array (
      0 => 'Expires: Wed, 11 Jan 1984 05:00:00 GMT',
      1 => 'Cache-Control: no-cache, must-revalidate, max-age=0',
      2 => 'Content-type: text/html; charset=UTF-8',
    )

    First 2 entries refer to WP core, specifically to wp-cron.php line 21:

    /* Don't make the request block till we finish, if possible. */
    if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
    	if ( ! headers_sent() ) {
    		header( 'Expires: Wed, 11 Jan 1984 05:00:02 GMT' );
    		header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    	}
    
    	fastcgi_finish_request();
    }

    Couldn’t figure out where 'Content-type: text/html; charset=UTF-8' is coming from though.

    The issue seems to arise from my cron job as it isn’t WP’s, but invoked by Linux. In wp-config.php I’ve:

    /** To use Linux crontab, make sure WP Cron is disabled */
    define('DISABLE_WP_CRON', true);

    The fix that seems to address the issue is adding this line to advanced-cache.php before setting any headers:

    if( defined( 'DOING_CRON' ) ) die();
    
    if( intval($swcfpc_config["cf_maxage"]) > 0 ) {
        header_remove('Set-Cookie');
    }
    Plugin Contributor Saumya Majumder

    (@isaumya)

    Hi @alx359,
    Thanks for the amazing test results. Yes the headers you showed above being sent before advance-cache.php are all WP core headers.

    Also thanks for sharing the possible workaround. Let @salvatorefresta take a look of this fix can be implemented or not in the upcoming update.

    BTW, I also use server level cron and not WP Cron just to let you know but after removing unnecessary lines at the end of my mu plugins & wp config the issue stopped showing on my end.

    alx359

    (@alx359)

    Thanks for confirming, Saumya.

    I already tried taking out health-check-troubleshooting-mode.php from mu-plugins, and later also tried your suggestion of cleaning up redundant symbols from the end of wp-config.php but neither of those helped in my case.

    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi @alx359 ,
    thank you so much! With the next update, the cache will be skipped if DOING_CRON is defined and true! 🙂

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.