• Resolved glouton

    (@glouton)


    Hi there,

    I have the following PHP warnings in my log:

    PHP Warning: Cannot modify header information – headers already sent in /wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    PHP Warning: session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/VetSaveur/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110

    WordPress version: 5.2.3
    PHP version: 7.3.9

    I’ve search for days and couldn’t find any ouput anywhere (no whitespace, no BOM… no nothing).
    With the headers_sent() function I’ve managed to narrow it down to wp-cron.php on line 23 with fastcgi_finish_request().

    Maybe session_start() as to be hooked differently. No error if I disable the cron.

    Regards,

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author webheadcoder

    (@webheadllc)

    It would be best to deactivate all other plugins except this one and the main CF7 plugin and switch to the default theme. Reactivate the plugins and your theme one by one until you get the error again.

    Thread Starter glouton

    (@glouton)

    Hello,

    Thank you for getting back to me promptly.

    I was pretty sure I had ruled out all other possible causes but to be on the safe side here’s what I’ve done :

    1. Install a fresh WordPress 5.2.3
    2. Install CF7
    3. Install CF7 Multi-Step

    On this brand new installation I didn’t have any error.
    Then after installing and activating CBX Poll it came back once. By the way I have open the same thread on their side: https://wordpress.org/support/topic/headers-already-sent-39/

    As I’ve previously managed to narrow it down to the WordPress schedule task system and their wp-cron.php file, I’ve quickly created a dummy plugin to register minutely task:

    
    <?php
    /**
     * Plugin Name: Cron Test
     */
    function my_add_minutely( $schedules ) {
        // add a 'minutely' schedule to the existing set
        $schedules['minutely'] = array(
            'interval' => 60,
            'display' => __('Once Minutely')
        );
        return $schedules;
    }
    add_filter( 'cron_schedules', 'my_add_minutely' );
    
    register_activation_hook(__FILE__, 'my_activation');
    
    function my_activation() {
        if (! wp_next_scheduled ( 'my_minutely_event' )) {
            wp_schedule_event(time(), 'minutely', 'my_minutely_event');
        }
    }
    
    add_action('my_minutely_event', 'do_this_minutely');
    
    function do_this_minutely() {
        // do something every minute
        error_log( 'My minutely event.' );
    }
    
    register_deactivation_hook(__FILE__, 'my_deactivation');
    
    function my_deactivation() {
            wp_clear_scheduled_hook('my_minutely_event');
    }
    

    And now I do have the PHP warning repeatedly:
    https://mega.nz/#!FzwzyYQa!Q_tHIjQJuV5Tdt1m_gXoJE_u9RO1nhKgPD5iBL92_vQ

    Regards,

    Thread Starter glouton

    (@glouton)

    PS: wonder who marked this as resolved…

    Plugin Author webheadcoder

    (@webheadllc)

    Apologies, from your response it looks like you figured out that the problem is not this plugin. You had only this plugin active and you had no errors. Once you activated the other plugin you saw your error. So it seems the problem lies in the other plugin.

    This plugin also doesn’t run anything in WP Cron and your cron test doesn’t run any of this plugin’s functions directly. So again, it seems this plugin is not the problem.

    Thread Starter glouton

    (@glouton)

    Hi there,

    I think I just proved to you that on the contrary there is a problem with this plugin and that CBX Poll plugin has the same one.

    Your plugin does not run anything in WP Cron but it does issue the error in log when the cron runs. This is precisely what my test above shows.
    Means it’s hooked somewhere the wrong way because it’s called when the cron runs.

    Please read my answer carefully once more.

    basically, WP Cron runs > Your plugin tries to start session.

    This is wrong and shouldn’t happen.
    Your plugin does not have any issue as long as no WP Cron task runs.
    But there are cron task even in core WordPress. Cron task in WooCommerce and many other very famous plugins.
    As a result, your plugin seems flawed.

    I think I’ve already done a lot of work for you trying to narrow down the problem.
    The least you could do is address it and have a look into it.

    PS: if you check the support thread on CBX Poll side you’ll see that their answer to this issue is “We are checking, will give feedback asap.”

    Plugin Author webheadcoder

    (@webheadllc)

    Looks like the other developers fixed the problem with their plugin and this is no longer happening.

    Thread Starter glouton

    (@glouton)

    (not saying hello as you never bothered)

    If by “the other developers” and “their plugin” you mean codeboxr, Sabuj Kundu and the CBX Poll plugin then yes indeed THEY looked into it and fixed THEIR plugin.

    You on the other hand didn’t fixed anything and plugin still face exactly the same issue.

    Again, as already said before, with only WordPress + CF7 + CF7 Multi-steps + my little plugin to run cron minutely and the warnings are having a party in the log.
    See install plugins in this screenshot:
    https://mega.nz/#!gm5RBITY!e1ul-bRC8Wb55O55b-u8M4gj2o2TrewE_WQv2YfMxXw

    I guess you can download their plugin and look at how they fixed it.
    I pointed you to the right direction telling you when and where it happens and even almost the why. It has something to do with PHP version >= 7.0
    From my original post “I’ve managed to narrow it down to wp-cron.php on line 23 with fastcgi_finish_request()”

    Here the log right now (again with only you plugin and a dummy cron task):

    
    [23-Sep-2019 07:54:58 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 07:54:58 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 07:54:58 UTC] My minutely event.
    [23-Sep-2019 07:56:33 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 07:56:33 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 07:56:33 UTC] My minutely event.
    [23-Sep-2019 08:01:41 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:01:41 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:01:41 UTC] My minutely event.
    [23-Sep-2019 08:02:44 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:02:44 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:02:44 UTC] My minutely event.
    [23-Sep-2019 08:04:44 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:04:44 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:04:44 UTC] My minutely event.
    [23-Sep-2019 08:06:36 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:06:36 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:06:36 UTC] My minutely event.
    [23-Sep-2019 08:07:36 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:07:36 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:07:36 UTC] My minutely event.
    [23-Sep-2019 08:09:36 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:09:36 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:09:36 UTC] My minutely event.
    [23-Sep-2019 08:11:36 UTC] PHP Warning:  Cannot modify header information - headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 106
    [23-Sep-2019 08:11:36 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /Nightcrawler/projects/WordPress/www/wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php on line 110
    [23-Sep-2019 08:11:36 UTC] My minutely event.

    If you don’t want to fix it that’s not of my business, I have remove your plugin anyway and wasted way enough time with that.

    Plugin Author webheadcoder

    (@webheadllc)

    My bad, you said “On this brand new installation I didn’t have any error”. Then you mentioned activating the other plugin and that errors are occurring during wp-cron.

    However, i still can’t reproduce your warnings. Like I said before, I have the CF7 Multi-Step Forms plugin and wp-cron running on several sites with no warnings.

    The only way I can get your warning is by copying your code exactly (with the space above the “<?php”) and activating your code. Once activated I get the “Cannot modify headers error”. I’m assuming the empty first line is just a formatting thing when posting to the forum, but that’s the only way I can get the error.

    When it runs every minute I do not get any warnings. I’ve tried this on PHP 5.4.13 and PHP 7.3.1.

    Something that might be triggering the warning on your server might be the setcookie function being written on multiple lines. totally a shot in the dark, but that’s the only weird thing I can see on that line number.

    If you’re still interested in getting this error resolved, could you try replacing the call to setcookie around line 106? Currently the arguments are on multiple lines. basically I would like to see if anything gets resolved if it’s all on one line like:
    setcookie('cf7msm_check', 1, 0, COOKIEPATH, COOKIE_DOMAIN);
    And also maybe replace COOKIEPATH and COOKIE_DOMAIN with empty strings “”.

    If you’ve already moved on that’s fine too.

    On side note, to run WP-Cron you could use WP-Cron Status Checker (another of one my plugins) or WP Crontrol

    Plugin Author webheadcoder

    (@webheadllc)

    You could also possibly try adding an exit; right before the session_start() and see what it prints. You would have to visit wp-cron.php directly

    Thread Starter glouton

    (@glouton)

    Hi,

    The empty first line is just a formatting thing when posting to the forum indeed.
    Of course I don’t have it in orignal code, set nobomb in Vim and checked for trailing white spaces with phptags.

    Furthermore let me remind you that I first had these warnings on a real project.
    I added this little cron-test only to confirm what I found after days of digging.

    Maybe you can’t reproduce because you did not enable WP_DEBUG and WP_DEBUG_LOG.
    If this is the case I suggest that you do. Simplest way is to copy paste the example at the bottom of this WordPess Codex page:

    Debugging in WordPress

    Plugin Author webheadcoder

    (@webheadllc)

    Sorry I still can’t see anything in the logs except the “My minutely event.”. I created a new wordpress install, turned on WP_DEBUG and WP_DEBUG_LOG and debug.log was the same as the regular error logs.

    Just to confirm, you have only these 3 plugins active:
    Contact Form 7 v5.1.4
    Contact Form 7 Multi-Step Forms v3.1.1
    Cron Test (your plugin)

    and the Theme is the Twenty Nineteen theme v1.4

    I can take a look at your install if you want. email me the login info at corey @ webheadcoder.com without the spaces. Preferably the clean install and not live so I can try things out.

    Have you tried adding exit; before the session_start()? I think that should exit the process and reveal whatever output is causing the error when you visit wp-cron.php.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hea’ is closed to new replies.