What are the advantages and disadvantages of using gzip archives over ZIP files in PHP?

When comparing gzip archives to ZIP files in PHP, gzip archives are generally more efficient in terms of compression ratio and speed. However, ZIP files offer better support for creating and extracting archives with multiple files and directories.

// Using gzip to compress a file
$file = 'example.txt';
$gzippedFile = $file . '.gz';

$fp = gzopen($gzippedFile, 'w9');
gzwrite($fp, file_get_contents($file));
gzclose($fp);

// Extracting a gzip file
$unzippedFile = 'example_unzipped.txt';

$zp = gzopen($gzippedFile, 'r');
$fp = fopen($unzippedFile, 'w');

while (!gzeof($zp)) {
    fwrite($fp, gzread($zp, 4096));
}

gzclose($zp);
fclose($fp);