apache - Disable gzip compression on Openshift (php cartridge)

951

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'); andapache_setenv('dont-vary', '1'); in the php file
  • SetEnv no-gzip dont-vary in the .htaccess file

Still a simple test viacurl -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
431

Answer

Solution:

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 useCache-Control: no-transform response header, and it didn't work.

People are also looking for solutions to the problem: php - CodeIgniter controller method not responding

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.