Reputation: 7688
Does any body has any idea how to find where the leak is that provokes this "Content Encoding Error" with $config['compress_output'] = true
in CodeIgniter?
I've trying to debug this error for days, but I can't seem to find where the leak is. LogLevel
is at debug
but I see no info in the log when this error happens.
So, any ideas how to debug this?
I really don't want to disable the compress_output
feature, I just want to see how can I trace where the error is produced
I've looked over and over again to see if there is any output in the controllers... and there is none, so some where else must be the error provoked. No models/database, just controllers, libraries, helpers and views
Upvotes: 7
Views: 12384
Reputation: 1
Some CPanel lightspeed extension updates create this problem. You can try adding this code in your .htaccess
file:
php_flag zlib.output_compression ON
Upvotes: 0
Reputation: 21
Putting the following line in config.php:
$config['compress_output'] = FALSE;
Solves it. The problem in my case was that I sent the post, but it did not recognize the FILLCATEGORIAS
function. Inly by changing the $ config [ 'compress_output'] = FALSE;
solved it.
THIS problem occurred when we send data using a POST request:
Failed to load resource: net::ERR_CONTENT_DECODING_FAILED
<script type="text/javascript">
$(document).ready(function() {
$("#idEmpresa").change(function() {
$("#idEmpresa option:selected").each(function() {
id = $('#idEmpresa').val();
$.post("<?php echo base_url();?>Admin/fillCategorias", {
idEmpresa : id
}, function(data) {
$("#idCategoria").html(data);
});
});
});
});
</script>
Upvotes: 2
Reputation: 2345
I had the same problem. After searching, I found that my controller has ?>
at end of file. So I removed it and it works perfectly. Here is a link for more detail.
Upvotes: 1
Reputation: 5726
Any error in PHP will break compression.
To test this, in index.php change:
error_reporting(E_ALL);
to
error_reporting(E_ALL ^ E_NOTICE);
Do not echo/print to display output from controller.
Do not use "?>" at the end of controller file.
I hope it helps.
Update:
To check if the output is empty before starting buffering, you can open core/Output.php and add
ob_flush();
before
ob_start('ob_gzhandler');
If there is even a space or an empty line, compression will fail. (check page source from browser). This happens because with $config[‘compress_output’] = true , ob_start('ob_gzhandler') (line 379 in Output.php) is executed, wich will cause a "Cannot modify header information - Headers already sent ..." warning. This warning is the cause of compression failure.
So basically, any echo outside of Output class (json output included) will send headers to client, which will cause "Cannot modify header information - Headers already sent ..." warning, which will cause the "content encoding error".
Upvotes: 1
Reputation: 657
This might be a long shot, but if you echo/print database output directly from your controller instead of sending it to the model you'll likely get error messages that have to do with output buffering. Are you echoing from your controller?
Upvotes: 2
Reputation: 606
This issue is where the output buffering starts. The check for the config variable is in system/core/Output.php
in _display()
. It starts the gzipped buffering after a lot of code has already run. This leaves the potential for output to have occurred before it buffering starts.
With compress_output
set to false
it doesn't matter because nothing is encoded. With it set to true
you end up with mixed content. Some output is encoded and some is not which causes the compression error.
There are two solutions:
1) You could leave compress_output
set to false and add ob_start('ob_gzhandler');
to the top of your index.php file. This will ensure that all output is always gzipped, including errors.
2) The other solution is to add ob_flush();
before ob_start('ob_gzhandler');
in system/Output.php
. This will gzip output when there are no errors and serve you unencoded content when there are errors.
I think 2 is the better solution and should be implemented by the CodeIgniter team. But if you don't want to muck with the system code (changes will go away when you upgrade) then 1 is the better solution for you.
Upvotes: 19