Please be aware that, as other users have already mentioned, the compression will fail if there are characters before the php start tag "< ?".
This is also the case when saving files in UTF-8 format with editors such as Ultraedit. Make sure you save the file using the defined option UTF-8 NO BOM or delete the BOM otherwise the two UTF BOM characters will be written at the start of the file.