1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Output buffering clearing causes notice error

Discussion in 'Resolved Bug Reports' started by AlexT, Jun 28, 2013.

  1. AlexT

    AlexT Well-Known Member

    Got this notice error in my log files (XF 1.2 beta 3):
    Code:
    Application.php(186)    ob_end_clean(): failed to delete buffer. No buffer to delete    E_NOTICE
    PHP:
    // see http://bugs.php.net/bug.php?id=36514
    if (!@ini_get('output_handler')) while (@ob_end_clean());
    It is caused by calling ob_end_clean() even if there is not a buffer.

    Not sure if this workaround fix is still needed for older PHP versions, but if it is, perhaps it could be enhanced with this line of code:
    PHP:
    if (!@ini_get('output_handler')) while (ob_get_level() > 0) { ob_end_clean(); };
    This will clean output buffering if and only if it's already started.
     
    Last edited: Jun 28, 2013
  2. AlexT

    AlexT Well-Known Member

    Forgot to mention, this test server runs:

    PHP 5.3.26 with output_buffering set to Off. Gzip is enabled by the web server (Nginx).
     
  3. Mike

    Mike XenForo Developer Staff Member

    That's generally the reason we use the shut up operator there. I'm not sure why that should be logged...
     
    Jeremy likes this.
  4. AlexT

    AlexT Well-Known Member

    Mike, I am using a debugger that shows all errors even with the dog-slow @ prefix . With the suggested fix I believe it should not be necessary to suppress the error anymore and still achieve what you wanted to.
     
  5. AlexT

    AlexT Well-Known Member

    I found this remark in the Mediawiki SVN:
    So perhaps above suggested code should be changed to:

    PHP:
    if (!@ini_get('output_handler'))
    {
        for (
    $i 0$i ob_get_level(); $i++)
        {
          
    ob_end_clean();
        }
    }
     
  6. Kier

    Kier XenForo Developer Staff Member

    I've applied the fix you noted in your last post there, but we're still testing...
     
    AlexT likes this.
  7. Mike

    Mike XenForo Developer Staff Member

    Yeah, I think that code is bugged. If it's deep within an output buffer, I don't think it cleans it properly. I'm looking at an alternative approach that doesn't use the shut up operator.
     
    Kier likes this.
  8. Mike

    Mike XenForo Developer Staff Member

    Trying:
    Code:
                $level = ob_get_level();
                while ($level)
                {
                    ob_end_clean();
                    $newLevel = ob_get_level();
                    if ($newLevel >= $level)
                    {
                        break;
                    }
                    $level = $newLevel;
                }
    As that should handle any infinite loop possibility (by the get level not changing correctly).
     
    Liam W, SneakyDave and AlexT like this.

Share This Page