I am trying to pack around 50 files from a folder to zip file using PHP ZipArchive. Actually, only at most five files are ever changing. Others remain same static files. Should I zip the folder for every request or just replace those five files. Which one would be better for memory consumption and performance?
<?php
$zip = new ZipArchive();
$zip->open('example.zip', ZipArchive::CREATE);
$srcDir = "/folderTobeZipped/";
$files= scandir($srcDir);
unset($files[0],$files[1]);
foreach ($files as $file) {
$zip->addFile("{$file}");
}
$zip->close();
?>