The error “Failed to send buffer of zlib output compression” usually occurs when the web server cannot send compressed data to the browser. Here are some causes and solutions. This error appears on the latest wordpress version. Some websites, even without any plugins installed, still have this error. Here are 3 ways to fix it Failed to send buffer of zlib output compression For your reference and follow.
Cause of error Failed to send buffer of zlib output compression
- Server configuration: Check the server configuration (such as Apache or Nginx) to ensure that zlib compression is enabled and configured properly. You can find compression related settings in the configuration file.
- Conflicts with plugins: If you are using a content management system like WordPress, there may be conflicts between plugins. Try disabling plugins temporarily to determine if any plugin is causing the problem.
- Memory full: Make sure your server is not running out of memory or disk space, as this may prevent the server from being able to perform compression and send data.
- Increase cache size: If you have access to PHP configuration, try increasing cache size by adjusting parameters like
output_buffering
. - Check for PHP errors: Check the PHP error log to see if there are any error messages related to this issue.
How to handle failed to send buffer of zlib output compression error
Here are the solutions I found to share with you:
SOLUTION 1:
In plugins (or somewhere) you can have this code:
ini_set('zlib.output_compression', '1');
so, i replaced that code with
if (!is_admin()) ob_start('ob_gzhandler'); //because, in admin pages, it causes plugin installation to freeze
and Compression will remain ON.
SOLUTION 2:
You may have to use:
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
SOLUTION 3:
/** * The ob_end_flush() function is suitable for all levels * * This function replaces the WordPress * `wp_ob_end_flush_all()` function with an alternative function that does not cause a PHP message. */ remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); add_action( 'shutdown', function() { while ( @ob_end_flush() ); } );
Below are detailed instructions for inserting the code you provide into your WordPress website:
How to insert code into WordPress
1. Use the Code Snippets plugin
The simplest way to add code to WordPress without editing theme files is to use the “Code Snippets” plugin.
- Step 1: Install the “Code Snippets” plugin.
- Go to the WordPress dashboard, select “Plugins” > “Add New”.
- Search for “Code Snippets” and install.
- Step 2: Add new code.
- After installation, go to “Snippets” > “Add New”.
- Give the snippet a name (e.g. “Compress output”).
- Paste the following code into the content box:
- // Solution 1
if (!is_admin()) ob_start('ob_gzhandler'); // Enable compression only on the frontend
- // Solution 2
remove_action('shutdown', 'wp_ob_end_flush_all', 1);
- //Solution 3
remove_action('shutdown', 'wp_ob_end_flush_all', 1);
add_action('shutdown', function() { while (@ob_end_flush()); });
- Step 3: Save and activate the snippet.
- Click “Save Changes and Activate” to save and activate the code.
2. Edit the theme's functions.php file
If you don't want to use a plugin, you can also insert the code into the file functions.php
of the theme in use.
- Step 1: Access the control panel.
- Step 2: Go to “Appearance” > “Theme Editor”.
- Step 3: Select file
functions.php
from the list on the right. - Step 4: Paste the code at the end of the file (before tag
?>
if any):
// Solution 1if (!is_admin()) ob_start('ob_gzhandler'); // Enable compression only on the frontend
// Solution 2
remove_action('shutdown', 'wp_ob_end_flush_all', 1);
//Solution 3
remove_action('shutdown', 'wp_ob_end_flush_all', 1); add_action('shutdown', function() { while (@ob_end_flush()); });
- Step 5: Click “Update file” to save changes.
Note
- Before making any changes, back up your website to avoid data loss.
- After inserting the code, test your website to make sure everything is working properly.
Conclude.
It is inevitable that users using WordPress will encounter errors. This article helps you handle the Failed to send buffer of zlib output compression error on WordPress. Hope it will be of great help to you. During the process, if you can't do it, please leave a comment below.
Also you can visit Facebook fanpage of howto.edu.vn us to update the latest information