tags:

views:

77

answers:

2

Hi, in the root directory of my webapp, the .htaccess file contains the following line:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript

This means that all my pages are gzipped, and it's ok.

In some pages I need to make the browser close the connection before the script ends (I need some time consuming postprocessing). To do so I do:

ignore_user_abort(true);
set_time_limit(0);
$str = ob_get_contents();
ob_end_clean();
header("Content-Length: ".strlen($str));
header('Connection: close');

Without compression it works, with the gzip compression enabled not: the browser renders the page but the loading wheel still runs.

The question is: is there a way (f.e. with ini_set()) to disable the gzip compression ONLY for some pages, from inside the php code?

+1  A: 

Just found something that might work. It prevents Apache from applying the gzip/defalte encoding. Not sore if it inhibits the filter module itself:

 header("Content-Encoding: idendity");

Or use the application/xhtml+xml Content-Type.

mario
Actually, the `Content-Type` change, using one that does not match the specified types work.I think I'll opt for this solution, thank you.
Iacopo
A: 

Actually, after a few tests, I've found that the accepted solution is not optimal:

  • apache overwrites the Content-Encoding header if compression is on,
  • changing the Content-Type has the disadvantage that you then MUST produce well formed XML (that is a PITA, given that web designers work on the HTML side).

A working solution is to disable the compression for good:

@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);

Taken from the excellent PHP documentation

Iacopo