Here’s a code to create and write the content from a url to a gz file.
In this example, we are copying the content of an rss feed to a gz file. RSS Feed is usually an xml file that’s why we are adding .xml before the .gz extension.
$content = 'http://example.com/rss/feed';
$gz = gzopen ( 'filename.xml.gz', 'w9' );
gzwrite ( $gz, $content );
gzclose ( $gz );