CodeIgniter Forums
CI 3 Page is not loading (About compress_output) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CI 3 Page is not loading (About compress_output) (/showthread.php?tid=65489)



CI 3 Page is not loading (About compress_output) - marksman - 06-16-2016

Hi, I'm new in CodeIgniter and I want to use compress_output to my application and the page is not loading when I'm going to echo a query result. anyone can help me please?


RE: CI 3 Page is not loading (About compress_output) - dmyers - 06-17-2016

The first thing you want to do is make sure you follow the instructions in the CodeIgniter config/config.php file.

I think you missed the part that states "Do not 'echo' any values with compression enabled."

DMyers

/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads. When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| Only used if zlib.output_compression is turned off in your php.ini.
| Please do not use it together with httpd-level output compression.
|
| 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.
|
*/


RE: CI 3 Page is not loading (About compress_output) - marksman - 06-17-2016

(06-17-2016, 03:56 AM)dmyers Wrote: The first thing you want to do is make sure you follow the instructions in the CodeIgniter config/config.php file.

I think you missed the part that states "Do not 'echo' any values with compression enabled."

DMyers

/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads.  When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| Only used if zlib.output_compression is turned off in your php.ini.
| Please do not use it together with httpd-level output compression.
|
| 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.
|
*/

I'm so sorry for missing to read the instruction. atleast now I know. thanks for being helpful. but I still have a question, Is it possible to compress specific pages in codeigniter?


RE: CI 3 Page is not loading (About compress_output) - dmyers - 06-24-2016

(06-17-2016, 07:03 AM)marksman Wrote:
(06-17-2016, 03:56 AM)dmyers Wrote: The first thing you want to do is make sure you follow the instructions in the CodeIgniter config/config.php file.

I think you missed the part that states "Do not 'echo' any values with compression enabled."

DMyers

/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads.  When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| Only used if zlib.output_compression is turned off in your php.ini.
| Please do not use it together with httpd-level output compression.
|
| 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.
|
*/

I'm so sorry for missing to read the instruction. atleast now I know. thanks for being helpful. but I still have a question, Is it possible to compress specific pages in codeigniter?

Hey no problem glad I could help.

If you want to do it on a page by page basis you probably want to extend the output library to enable/disable it dynamically.

something like:

$this->output->enable_compression(true); or $this->output->enable_compression(false);

You probably want to do something like in the output constructor to determine if it's even possible and then set outputs _compress_output appropriately. The library then should do the rest.

Hope that helps. 

DMyers


RE: CI 3 Page is not loading (About compress_output) - marksman - 06-24-2016

thanks dmyer.. I didnt try it yet but i beleive it will work.. thanks a lot for helping ?


RE: CI 3 Page is not loading (About compress_output) - dmyers - 06-26-2016

(06-24-2016, 03:04 PM)marksman Wrote: thanks dmyer.. I didnt try it yet but i beleive it will work.. thanks a lot for helping ?

I didn't try this code out but, it should get you rolling.

http://www.codeigniter.com/user_guide/general/core_classes.html?highlight=my_#extending-core-class

Code:
<?php 

class MY_Output extends CI_Output {

public function enable_compression($enable=true) {
/* if true */
if ($enable) {
/* are the right libraries even present? */
$this->_zlib_oc = (bool)ini_get('zlib.output_compression');

$this->_compress_output = ($this->_zlib_oc === FALSE && extension_loaded('zlib'));
} else {
/* guess you are turning it off */
$this->_compress_output = false;
}

/* chain-able */
return $this;
}

} /* end class */

Then in your controller you could use $this->output->enable_compression() to turn it on.