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/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax (/showthread.php?tid=27350) |
Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax - El Forum - 02-08-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; Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax - El Forum - 01-19-2011 [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. Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax - El Forum - 06-01-2011 [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: ... I solved with 2 more lines (explicit content type, and a die): Code: ... Hope this help Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax - El Forum - 06-01-2011 [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. |