Eric,
Have you compiled gzip support into PHP?
If so, just look at the gz* functions in PHP. If not, you will probably need to.
Take a look at
http://www.php.net/manual/en/function.gzopen.php
In the comments section, someone has done what you are trying to do!
Hope this helps,
Mark.