I just saw your question and was curious about it. So i made my own test-case. I left all the Servlet related stuff out of the problem and coded something like this:
import java.io.*;
import java.util.zip.GZIPOutputStream;
public class GZIPTestcase {
public static void main(String[] args) throws Throwable {
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(new File("/Users/malax/foo2.gz")));
PrintWriter pw = new PrintWriter(gzipOutputStream);
pw.println("All your base are belong to us!");
pw.flush();
pw.close();
}
}
The GNU gunzip was able to uncompress the data. Then i tries to uncompress it with PHP. It failed with the same error you got. I investigated further and found the following methods:
gzinflate does not work either, gzdecode is only shipped with PHP6 wich i havn't installed. Maybe you could try this. (According to http://bugs.php.net/bug.php?id=22123 this will work)
Im i doubt that the problem is on the Java side because GNU's gunzip can deflate the data so it must be correct. You might want to investigate further on the PHP side.
There is a realted question for .NET and PHP where the original poster has the same problem as you have: http://stackoverflow.com/questions/905328/can-php-decompress-a-file-compressed-with-the-net-gzipstream-class. PHP does not seem to be able to decompress the data from the .NET equivalent of the GZIPOutputStream either.
Sorry that i dont have a "solution" but i might have pointed you in the right direction anyways.
EDIT: I found an entry in the PHP Bugtracker which explains the problem:
http://bugs.php.net/bug.php?id=22967 It seems that gzuncompress cannot uncompress GZIP data with headers which will be produced be the GZIPOutputStream. As stated in the Bugtracker Entry, try to crop the header.