Disable gzip compression on Openshift (php cartridge)

1k views Asked by At

How do I disable gzip compression on Openshift (for specific requests)? More specific: For file downloads served by php - i.e. fpassthrough.

I tried several things:

  • ini_set('zlib.output_compression', 'Off'); in the php file
  • apache_setenv('no-gzip', '1'); and apache_setenv('dont-vary', '1'); in the php file
  • SetEnv no-gzip dont-vary in the .htaccess file

Still a simple test via curl -v -H 'Accept-Encoding: gzip,deflate' http://downloadtest-***.rhcloud.com gives:

> GET http://downloadtest-***.rhcloud.com/ HTTP/1.1
> User-Agent: curl/7.41.0
> Host: downloadtest-***.rhcloud.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> Accept-Encoding: gzip,deflate
>
< HTTP/1.1 200 OK
< Date: Fri, 22 May 2015 12:47:41 GMT
< Server: Apache/2.2.15 (Red Hat)
< Content-Disposition: attachment; filename="myfile.tmp"
< Content-Lenght: 54
< Content-Type: application/octet-stream
< Vary: Accept-Encoding
< Content-Length: 77
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
< Content-Encoding: gzip

Background: I need to disable gzip compression as it corrupts already gzipped files - see e.g. https://magento.stackexchange.com/questions/3528/downloadable-zip-files-are-corrupt or http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php.


The complete test code:

index.php:

$file = __DIR__ . '/test.txt.gz'; //This file is acutally 54 bytes

ini_set('zlib.output_compression', 'Off');

apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');

header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="myfile.tmp"');
header('Content-Lenght: '.filesize($file));

if(!file_exists($file)) {
    echo "file does not exist!\n";
    exit(0);
}
$handle = fopen($file, 'rb');
fpassthru($handle);
fclose($handle);
exit(0);

.htaccess:

RewriteEngine On
SetEnv no-gzip dont-vary
1

There are 1 answers

0
abacabadabacaba On

The compression is performed by OpenShift proxy, so the configuration of your server has no effect on it. I haven't found any way to disable the compression. For example, I tried to use Cache-Control: no-transform response header, and it didn't work.