$string = 'Some information to compress'; $gz = gzopen('somefile.gz','w9'); gzwrite($gz, $string); gzclose($gz);