Welcome Guest, Not a member yet? Register   Sign In
CI 3 Page is not loading (About compress_output)
#1

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?
God Bless CI Contributors Smile
Reply
#2

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.
|
*/
Reply
#3

(This post was last modified: 06-17-2016, 07:14 AM by marksman.)

(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?
God Bless CI Contributors Smile
Reply
#4

(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
Reply
#5

thanks dmyer.. I didnt try it yet but i beleive it will work.. thanks a lot for helping ?
God Bless CI Contributors Smile
Reply
#6

(This post was last modified: 06-26-2016, 10:43 AM by dmyers.)

(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/ge...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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB