WordPress.org

Make WordPress Core

Ticket #18525: 18525.6.diff

File 18525.6.diff, 3.7 KB (added by kurtpayne, 7 years ago)

Compatibility with ob_gzhandler

  • 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
  • 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 * ob_gzhandler will manage its own headers.  If you call ob_start('ob_gzhandler') and ob_end_clean()
     3289 * immediately afterwards, it will still send a Content-Encoding: gzip header, but the page will not
     3290 * be compressed, this usually leads to an encoding error in the browser
     3291 * @link http://us.php.net/ob_gzhandler
     3292 *
     3293 * For a more detailed explanation of this function, see
     3294 * @link http://core.trac.wordpress.org/ticket/18525
     3295 *
     3296 * @param bool $disable_compression Turn off zlib / gzip compression, attempt to defeat chunking.
     3297 * @return void
    32793298 * @since 2.2.0
    32803299 */
    3281 function wp_ob_end_flush_all() {
     3300function wp_ob_end_flush_all($disable_compression = false) {
     3301
     3302        // Send this string to fill up any buffers that php / apache / browser might have
     3303        $buffer_string = '<!--' . str_repeat(chr(0), 4089) . '-->'; // 4096 bytes
     3304       
     3305    // If the script is called through CLI for any reason, bail
     3306    if ( 'cli' == php_sapi_name() )
     3307        return;
     3308
     3309        // ob_gzhandler manages http headers.  When undoing it with
     3310        // ob_end_flush, the result is "Warning - headers already sent ..."
     3311        // just bail
     3312        if (in_array('ob_gzhandler', ob_list_handlers())) {
     3313                ob_flush();
     3314                return;
     3315        }
     3316
     3317        // Tell apache to send an uncompressed non-chunked response
     3318        if ( $disable_compression && !headers_sent() && function_exists('apache_setenv') ) {
     3319                apache_setenv( 'no-gzip', '1' );
     3320        }
     3321
     3322        // Turn off any default output handlers
     3323        ini_set('output_handler', '');
     3324        ini_set('output_buffering', false);
     3325        ini_set('implicit_flush', true);
     3326
     3327    // Clean the output buffer
    32823328        $levels = ob_get_level();
    3283         for ($i=0; $i<$levels; $i++)
    3284                 ob_end_flush();
     3329        for ($i=0; $i<$levels; $i++) {
     3330                @ob_end_flush();
     3331        }
     3332
     3333        // Turn off the zlib compression handler
     3334        if ( $disable_compression ) {
     3335                if ( !headers_sent() && ini_get('zlib.output_handler') ) {
     3336                        ini_set('zlib.output_handler', '');
     3337                        ini_set('zlib.output_compression', 0);
     3338                }
     3339
     3340                // Pad the output by a 4K block to ensure that the server / browser
     3341                // considers the output sufficient
     3342                if (headers_sent()) {
     3343                        echo $buffer_string;
     3344                        flush();
     3345                }
     3346        }
    32853347}
    32863348
    32873349/**
  • 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 ) {