3

I have a configuration that doesn't seem too common on the Internets (PHP with IIS), and so far I have not been able to find a solution for my problem because of this.

Basically when I'm sending a manual 404 header on my php page:

header('HTTP/1.0 404 Not Found');

The problem is that I then always get encoding errors, which I've determined has something to do with gzip being enabled.

When I curl with --compressed I get:

HTTP/1.1 404 Not Found
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 3560
Content-Type: text/html
Content-Encoding: gzip
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Vary: Accept-Encoding
Server: Microsoft-IIS/6.0
Set-Cookie: PHPSESSID=b0ueqhtc3o4p7m2luqss170fr3; path=/
Date: Mon, 11 Jul 2011 16:15:40 GMT

curl: (61) Error while processing content unencoding: invalid code lengths set

Is it possible to disable compression just for this one page? Or is there some other solution for this that I'm missing? I don't want to disable compression for the entire site.

catbelly
  • 500
  • 4
  • 16

1 Answers1

8

This is simple, just use the ini set like so:

<?php 
    if(ini_get('zlib.output_compression')){ 
        ini_set('zlib.output_compression', 'Off'); 
    }
    header('HTTP/1.0 404 Not Found');
?>

Simple as that.

BrandonS
  • 932
  • 7
  • 16
  • my hero! I saw a bunch of things saying ini_set didn't work for that setting and I guess I just believed them without actually trying it... – catbelly Jul 11 '11 at 17:59
  • NP I'm glad that it worked for you, as with output compression there are a lot of things in a windows / php enviroment that you will find that way. something that works on 1000 other setups like yours but not on yours and vice versa you just have to use trial and error. There are literally thousands of configurations between windows IIS and PHP that can disable/enable even the most fundamental functions and drive you insane. – BrandonS Jul 11 '11 at 18:05