Make WordPress Core

Ticket #18525: 18525.5.diff

File 18525.5.diff, 2.9 KB (added by kurtpayne, 13 years ago)

Suppressing ob_end_flush notices, bailing during CLI mode

  • wp-includes/functions.php

     
    32753275 * Flush all output buffers for PHP 5.2.
    32763276 *
    32773277 * Make sure all output buffers are flushed before our singletons our destroyed.
    3278  *
     3278 * Only use $disable_compression for pages that need to be updated continuously, like updating the core,
     3279 * or installing plugins, etc.
     3280 *
     3281 * Turn off compression - make sure to flush the buffer BEFORE
     3282 * turning off compression, see comment from Sam Yong
     3283 * @link http://php.net/manual/en/function.ob-end-clean.php
     3284 *
     3285 * Turn off mod_deflate
     3286 * @link http://httpd.apache.org/docs/2.2/env.html#no-gzip
     3287 *
     3288 * For a more detailed explanation of this function, see
     3289 * @link http://core.trac.wordpress.org/ticket/18525
     3290 *
     3291 * @param bool $disable_compression Turn off zlib / gzip compression, attempt to defeat chunking.
     3292 * @return void
    32793293 * @since 2.2.0
    32803294 */
    3281 function wp_ob_end_flush_all() {
    3282         $levels = ob_get_level();
    3283         for ($i=0; $i<$levels; $i++)
    3284                 ob_end_flush();
     3295function wp_ob_end_flush_all($disable_compression = false) {
     3296
     3297    // If the script is called through CLI for any reason, bail
     3298    if ( 'cli' == php_sapi_name() )
     3299        return;
     3300   
     3301    // Clean the output buffer
     3302    $levels = ob_get_level();
     3303    for ($i=0; $i<$levels; $i++)
     3304        @ob_end_flush();
     3305
     3306    if ( $disable_compression ) {
     3307        if ( !headers_sent() && ini_get('zlib.output_handler') ) {
     3308            ini_set('zlib.output_handler', '');
     3309            ini_set('zlib.output_compression', 0);
     3310        }
     3311
     3312        // Tell apache to send an uncompressed non-chunked response
     3313        if ( function_exists('apache_setenv') )
     3314            apache_setenv( 'no-gzip', '1' );
     3315
     3316        // Turn off any default output handlers
     3317        ini_set('output_handler', '');
     3318        ini_set('output_buffering', false);
     3319        ini_set('implicit_flush', true);
     3320
     3321        // Pad the output by a 4K block to ensure that the server / browser
     3322        // considers the output sufficient
     3323        echo '<!--' . str_repeat(chr(0), 4089) . '-->'; // 4096 bytes
     3324        flush();
     3325    }
    32853326}
    32863327
    32873328/**
  • wp-admin/includes/misc.php

     
    271271                        $message = $message->get_error_message();
    272272        }
    273273        echo "<p>$message</p>\n";
    274         wp_ob_end_flush_all();
    275         flush();
     274        wp_ob_end_flush_all(true);
    276275}
    277276
    278277function wp_doc_link_parse( $content ) {
  • wp-admin/includes/class-wp-upgrader.php

     
    12391239        }
    12401240
    12411241        function flush_output() {
    1242                 wp_ob_end_flush_all();
    1243                 flush();
     1242                wp_ob_end_flush_all(true);
    12441243        }
    12451244}
    12461245