CodeIgniter "Content Encoding Error"

Does any authority have any ideas on how to find the leak that causes this "Content Encoding" error with $config['compress_output'] = true in CodeIgniter?

I am trying to debug this error in a few days, but I can not find where the leak is. LogLevel is in debug , but I do not see any information in the log when this error occurs.

So, any ideas how to debug this?

UPDATE

I really don't want to disable the compress_output function, I just want to see how I can track where the error occurred

UPDATE2

I looked over and over again to see if there is any output in the controllers ... and they are not there, so some of them should be caused by an error. No models / database, just controllers, libraries, helpers and views

+6
source share
5 answers

This problem begins with output buffering. The check for the configuration variable is in system/core/Output.php in _display() . It starts gzipped buffering after a lot of code is already running. This leaves the potential for data output before buffering begins.

If compress_output set to false , it does not matter because nothing is encoded. When it is set to true , you will get mixed content. Some output is encoded, and some of them do not result in a compression error.

There are two solutions:

1) You can leave compress_output set to false and add ob_start('ob_gzhandler'); to the top of your index.php file. This ensures that all output is always gzipped, including errors.

2) Another solution is to add ob_flush(); before ob_start('ob_gzhandler'); in system/Output.php . This will output gzip when there are no errors, and serve you unencrypted when there are errors.

I think 2 is the best solution and should be implemented by the CodeIgniter team. But if you do not want to guess the system code (the changes will go away during the upgrade), then 1 is the best solution for you.

+15
source
  • Any error in PHP will break compression.

    To check this, change index.php:

     error_reporting(E_ALL); 

    to

     error_reporting(E_ALL ^ E_NOTICE); 
  • No echo / print for outputting output from the controller.

  • Do not use "?>" At the end of the controller file.

Hope this helps.

Update:

To check if it is empty before buffering starts, 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 the source of the page from the browser). This happens because with $ config ['compress_output] = true, ob_start (' ob_gzhandler ') is executed (line 379 in Output.php), which will lead to the warning "Unable to change header information - Headers have already been sent ...". This warning causes compression to fail.

Thus, any echo outside the Output class (including json output) sends headers to the client, which will result in the warning “Unable to change header information - Headers have already been sent ...”, which will cause a “content encoding error”.

+1
source

I had the same problem. After searching, I found that my controller has ?> At the end of the file. So I deleted it and it works great. See the link for more details.

+1
source

Put the following line in config.php:

 $config['compress_output'] = FALSE; 

Decides. The problem in my case was that I sent a message, but it did not recognize the FILLCATEGORIAS function. Only by changing $ config [ 'compress_output'] = FALSE; decided 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> 
+1
source

This may be a long snapshot, but if you echo / print the database directly from your controller and not send it to the model, you will most likely receive error messages related to output buffering. Are you echoing from your controller?

0
source

Source: https://habr.com/ru/post/917735/


All Articles