CodeIgniter Forums
Output.php with compress_output = true, always calls ob_start('ob_gzhandler') causing warning with ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Output.php with compress_output = true, always calls ob_start('ob_gzhandler') causing warning with ajax (/thread-26686.html)



Output.php with compress_output = true, always calls ob_start('ob_gzhandler') causing warning with ajax - El Forum - 01-20-2010

[eluser]Mitchell[/eluser]
Using CI with jquery/ajax, I encountered an error that took me quite a while to track down. This only occurs with $config['compress_output'] = true.

Here's the sequence:

1. Make ajax request with datatype = json to controller function

2. Controller function ends with: echo json_encode($data) in order to return data to javascript/jquery.

3. If $config['compress_output'] == true, then in file Output.php, line 287, ob_start('ob_gzhandler') is executed. If this line is executed, then the classic warning: "Cannot modify header information - Headers already sent" occurs. The error message refers back to the line in step 2: echo json_encode($data). In this particular situation, the variable $output is empty because the controller function is not loading a view.

4. If I either comment out the line ob_start('ob_gzhandler') or set compress_output = false, then the warning does not occur.

5. My guess for a fix would be to add the condition (&& $output != '') before calling ob_start().

6. Current work around is to add 2 lines before the end of the controller function:
global $CFG;
$CFG->config['compress_output'] = FALSE;