0

For creating xml-files I use the DOMObject. But all the created xml-files are big and would cause a heavy bandwidth.

This is the way I save the xml-file

$xml->save($filename);

How could I add a gzip compression?

EDIT: This snippet doesn't work because it creates an empty file

$gz = gzopen($filename,'w');
gzwrite($gz, $xml);
gzclose($gz);
Ronny Linsener
  • 253
  • 3
  • 16

1 Answers1

0

Here is just a .zip implementation.

$file   = '...';
$folder = 'folder';

$zip      = new ZipArchive();
$fileName = "some_file.zip";

if ($zip->open($fileName, ZIPARCHIVE::CREATE)!==TRUE) {
     throw new Exception('Can not create zip file.');
}

$zip->addEmptyDir($folder);

if (file_exists($file)) {
    $zip->addFile($file, $folder . "/" . basename($file));
}

$zip->close();
hakre
  • 193,403
  • 52
  • 435
  • 836
cmorrissey
  • 8,493
  • 2
  • 23
  • 27
  • 3
    I solved it with $xml->save('compress.zlib://' . $filename . '.gz'); – Ronny Linsener Oct 16 '13 at 19:20
  • @Ronny Linsener: That's the correct way and you find this asked and answered here: [How do you create a .gz file using PHP?](http://stackoverflow.com/q/6073397/367456) - I therefore voted to close against the duplicate to make the relation more tight. – hakre Oct 22 '13 at 12:51