I'm creating a zip archive using PHP's ZipArchive functions. My code performs well enough on small archives but on larger jobs, the time difference between running the PHP script from the shell and running it from a browser is just ridiculous.
The script below, for instance, executes in ~37 seconds from the shell but takes a whopping ~18 minutes when called with a browser. (It may seem nonsensical to be zipping a zip file, but I'll actually be zipping a collection of different file types (which often include zip files) and in this case, the 353MB zip file is the bottleneck so that's what I'm testing with.)
I've tried using PHP's exec() to zip the file using the OS's zip function with similar results. The code was fast in the shell but slowed to a crawl when executed by a browser.
I've found a few references to similar issues online, but none with a resolution. Does anyone have an idea why running this code with a browser results in a 3,000% performance hit?
I'm only using zip to package a collection of files for download and don't really care if the archive is compressed. Tar might be a viable choice, but end users won't know what to do with a tar file, and tgz is also off the table for the same reason. I'm open to another packaging format but off the top of my head, I can't think of another packaging method as ubiquitous as Zip.
Any thoughts?
The script below, for instance, executes in ~37 seconds from the shell but takes a whopping ~18 minutes when called with a browser. (It may seem nonsensical to be zipping a zip file, but I'll actually be zipping a collection of different file types (which often include zip files) and in this case, the 353MB zip file is the bottleneck so that's what I'm testing with.)
I've tried using PHP's exec() to zip the file using the OS's zip function with similar results. The code was fast in the shell but slowed to a crawl when executed by a browser.
I've found a few references to similar issues online, but none with a resolution. Does anyone have an idea why running this code with a browser results in a 3,000% performance hit?
I'm only using zip to package a collection of files for download and don't really care if the archive is compressed. Tar might be a viable choice, but end users won't know what to do with a tar file, and tgz is also off the table for the same reason. I'm open to another packaging format but off the top of my head, I can't think of another packaging method as ubiquitous as Zip.
Any thoughts?
Code:
<?php
$zip = new ZipArchive;
$f = array('attach/service/2016/02/12200/353MB.zip');
if($zip->open('test.zip',false ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) === true) {
foreach($f as $file)
{
$zip->addFile($file);
}
$zip->close();
echo "ok\n";
} else {
echo "failed\n";
}