CodeIgniter Forums
compression problem and wrong MIMIC - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: compression problem and wrong MIMIC (/thread-22189.html)



compression problem and wrong MIMIC - El Forum - 09-01-2009

[eluser]Dennis_gull[/eluser]
Hi,
My server doesn't allow apache gzip / deflate so I had to compress my php/js/css files with php. However when I turn the option on in the config.php file I will get the below Fatal error when I try to call an ajax function, any ideas why I get this error message?

Quote:<b>Fatal error</b>: ob_start() [&lt;a href='ref.outcontrol'&gt;ref.outcontrol&lt;/a&gt;]: Cannot use output buffering in output buffering display handlers in <b>/home/xxxxxx/public_html/system/libraries/Exceptions.php</b> on line <b>160</b><br />
All my ajax pages uses a controller + model (no view) so maybe I can turn gzip off in the ajax page, if so how does it work?


My second question is quite weired, when I use the RewriteEngine to hide the index.php I will get the wrong MIME type on my only png file which I load from a css file, the below message is shown when I monitor the http traffic in google chrome:

Quote:Resource interpreted as image but transferred with MIME type text/plain.

This is my .htaccess:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.js|(.*)\.png|(.*)\.jpg|(.*)\.gif|(.*)\.bmp|(.*)\.swf|(.*)\.css|robots\.txt|(.*)\.html|(.*).xml)
RewriteRule ^(.*)$ /u/index.php/$1 [L]

so if I comment out line 2 and 3 the MIMI type will work as it should, from what I see png files shouldn't get affected by the above code...


compression problem and wrong MIMIC - El Forum - 09-01-2009

[eluser]pistolPete[/eluser]
[quote author="Dennis_gull" date="1251816982"] any ideas why I get this error message?[/quote]

Just read the comment above the setting:
Code:
/* ...
| VERY IMPORTANT:  If you are getting a blank page when compression is enabled it
| means you are prematurely outputting something to your browser. It could
| even be a line of whitespace at the end of one of your scripts.  For
| compression to work, nothing can be sent before the output buffer is called
| by the output class.  Do not "echo" any values with compression enabled.
|
*/
$config['compress_output'] = TRUE;
You must use a view, don't echo from the controller.
You could use a very simple view like this:

ajax_view.php
Code:
&lt;?php
echo $ajax_data;

ajax_controller.php
Code:
&lt;?php
class Ajax_controller extends Controller {

    function some_function()
    {
        $data = array('ajax_data' => 'some data');
        $this->load->view('ajax_view', $data);
    }
}



compression problem and wrong MIMIC - El Forum - 09-01-2009

[eluser]Dennis_gull[/eluser]
I didn't think about reading the comment above the option Tongue
Thanks for pointing this out..

Any ideas on the second issue?


compression problem and wrong MIMIC - El Forum - 09-01-2009

[eluser]John_Betong[/eluser]
[quote author="Dennis_gull" date="1251845707"]I didn't think about reading the comment above the option Tongue
Thanks for pointing this out..

Any ideas on the second issue?[/quote]
&nbsp;
For your first point I stumbled upon this code from some knowledgeable code/poster.
It solved one of my problems:
Code:
if (LOCALHOST) // DO NOT compress $result
{
    // DO NOT COMPRESS
}else{
     // display in view
  $_SESSION['zzz_before'] = strlen($result);
    $search = array
            (
            '/\>[^\S ]+/s',    //strip whitespaces after tags, except space
            '/[^\S ]+\</s',    //strip whitespaces before tags, except space
            '/(\s)+/s'    // shorten multiple whitespace sequences
        );
    $replace = array
            (
            '>',
            '<',
            '\\1'
        );
    $result = preg_replace($search, $replace, $result);
            
    $result .= sprintf('%6.3f', $_SESSION['zzz_after'] / $_SESSION['zzz_before']) ;                                                            
    
     // display in view
    $_SESSION['zzz_after'] = strlen($result);

}//endcompress
&nbsp;
&nbsp;
&nbsp;