Ticket #18525: 18525.5.diff

File 18525.5.diff, 2.9 KB (added by kurtpayne, 20 months ago)

Suppressing ob_end_flush notices, bailing during CLI mode

Line 
1Index: wp-includes/functions.php
2===================================================================
3--- wp-includes/functions.php   (revision 18899)
4+++ wp-includes/functions.php   (working copy)
5@@ -3275,13 +3275,54 @@
6  * Flush all output buffers for PHP 5.2.
7  *
8  * Make sure all output buffers are flushed before our singletons our destroyed.
9- *
10+ * Only use $disable_compression for pages that need to be updated continuously, like updating the core,
11+ * or installing plugins, etc.
12+ *
13+ * Turn off compression - make sure to flush the buffer BEFORE
14+ * turning off compression, see comment from Sam Yong
15+ * @link http://php.net/manual/en/function.ob-end-clean.php
16+ *
17+ * Turn off mod_deflate
18+ * @link http://httpd.apache.org/docs/2.2/env.html#no-gzip
19+ *
20+ * For a more detailed explanation of this function, see
21+ * @link http://core.trac.wordpress.org/ticket/18525
22+ *
23+ * @param bool $disable_compression Turn off zlib / gzip compression, attempt to defeat chunking.
24+ * @return void
25  * @since 2.2.0
26  */
27-function wp_ob_end_flush_all() {
28-       $levels = ob_get_level();
29-       for ($i=0; $i<$levels; $i++)
30-               ob_end_flush();
31+function wp_ob_end_flush_all($disable_compression = false) {
32+
33+    // If the script is called through CLI for any reason, bail
34+    if ( 'cli' == php_sapi_name() )
35+        return;
36+   
37+    // Clean the output buffer
38+    $levels = ob_get_level();
39+    for ($i=0; $i<$levels; $i++)
40+        @ob_end_flush();
41+
42+    if ( $disable_compression ) {
43+        if ( !headers_sent() && ini_get('zlib.output_handler') ) {
44+            ini_set('zlib.output_handler', '');
45+            ini_set('zlib.output_compression', 0);
46+        }
47+
48+        // Tell apache to send an uncompressed non-chunked response
49+        if ( function_exists('apache_setenv') )
50+            apache_setenv( 'no-gzip', '1' );
51+
52+        // Turn off any default output handlers
53+        ini_set('output_handler', '');
54+        ini_set('output_buffering', false);
55+        ini_set('implicit_flush', true);
56+
57+        // Pad the output by a 4K block to ensure that the server / browser
58+        // considers the output sufficient
59+        echo '<!--' . str_repeat(chr(0), 4089) . '-->'; // 4096 bytes
60+        flush();
61+    }
62 }
63 
64 /**
65Index: wp-admin/includes/misc.php
66===================================================================
67--- wp-admin/includes/misc.php  (revision 18899)
68+++ wp-admin/includes/misc.php  (working copy)
69@@ -271,8 +271,7 @@
70                        $message = $message->get_error_message();
71        }
72        echo "<p>$message</p>\n";
73-       wp_ob_end_flush_all();
74-       flush();
75+       wp_ob_end_flush_all(true);
76 }
77 
78 function wp_doc_link_parse( $content ) {
79Index: wp-admin/includes/class-wp-upgrader.php
80===================================================================
81--- wp-admin/includes/class-wp-upgrader.php     (revision 18899)
82+++ wp-admin/includes/class-wp-upgrader.php     (working copy)
83@@ -1239,8 +1239,7 @@
84        }
85 
86        function flush_output() {
87-               wp_ob_end_flush_all();
88-               flush();
89+               wp_ob_end_flush_all(true);
90        }
91 }
92