This worked unstable for me under high load (50+ files per second):
<?php
$gz = gzopen ( $file, 'w9' );
gzwrite ( $gz, $content );
gzclose ( $gz );
?>
The following works fine:
<?php
$f = fopen ( $file, 'w' );
fwrite ( $f, gzcompress ( $content, 9 ) );
fclose ( $f );
?>