• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax

#1
[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;

#2
[eluser]softark[/eluser]
I'm experiencing the same problem. But not always.

1) running environment (php 5.1.6 linux hosting server)

1-a) compress_output = FALSE + non AJAX output ... OK
1-b) compress_output = FALSE + AJAX output ... OK
1-c) compress_output = TRUE + non AJAX output ... OK
1-d) compress_output = TRUE + AJAX output ... OK

2) development environment (php 5.3.1 win xampp server)

2-a) compress_output = FALSE + non AJAX output ... OK
2-b) compress_output = FALSE + AJAX output ... OK
2-c) compress_output = TRUE + non AJAX output ... OK
2-d) compress_output = TRUE + AJAX output ... NG !!!

So, it seems that some difference between those environment
has some relation to the problem. I don't know for sure.

#3
[eluser]Felice Ostuni[/eluser]
I ve the same problem on php 5.2 (and CI 1.7.3) with $config['compress_output'] = TRUE;

problem is on "ajax methods" where I send output with somethings like (innstead using views):
Code:
...
echo json_encode($myarray);

I solved with 2 more lines (explicit content type, and a die):
Code:
...
header("Content-type: application/json; charset=utf-8");
echo json_encode($myarray);
die;

Hope this help

#4
[eluser]CroNiX[/eluser]
Havent looked into it but it seems that you can extend Output.php and check for $_SERVER['HTTP_X_REQUESTED_WITH'] and if its present don't compress.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.