【问题标题】:Disable gzip compression on Openshift (php cartridge)在 Openshift 上禁用 gzip 压缩(php 墨盒)
【发布时间】:2015-08-04 12:30:39
【问题描述】:

如何在 Openshift 上禁用 gzip 压缩(针对特定请求)?更具体:对于 php 提供的文件下载 - 即 fpassthrough。

我尝试了几件事:

  • ini_set('zlib.output_compression', 'Off'); 在 php 文件中
  • apache_setenv('no-gzip', '1'); 和 apache_setenv('dont-vary', '1'); 在 php 文件中
  • SetEnv no-gzip dont-vary 在 .htaccess 文件中

仍然是通过curl -v -H 'Accept-Encoding: gzip,deflate' http://downloadtest-***.rhcloud.com 进行的简单测试:

> 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

背景: 我需要禁用 gzip 压缩,因为它会损坏已经 gzip 压缩的文件 - 参见例如https://magento.stackexchange.com/questions/3528/downloadable-zip-files-are-corrupt 或 http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php。


完整的测试代码:

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

【问题讨论】:

    标签: php apache gzip openshift openshift-php-cartidges


    【解决方案1】:

    压缩是由OpenShift proxy执行的,所以你服务器的配置对它没有影响。我还没有找到任何方法来禁用压缩。例如,我尝试使用Cache-Control: no-transform 响应头,它是didn't work。

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 2017-05-01
      • 2011-10-11
      • 1970-01-01
      • 2014-01-06
      相关资源
      最近更新 更多