AtlasC1 Posted October 24, 2012 Share Posted October 24, 2012 Hi everyone, I've been working on a Drupal-based Laboratory Information Management Systems (LIMS), and am having some issues with zipping files on the fly. It seems that, whenever the total content of the zip exceeds 85 MB, the download fails: the .zip file downloads, but is 0 bytes in size, and a .zip.download file also appears (which gives me the impression the download isn't complete). When I try extracting the .zip, it yields a .zip.cpgz file, which upon extracting, yields another .zip, and so on... Has anyone had an issue similar to this? Could it be timing out? It works fine for any number of files being zipped, as long as the total content is less than 85 MB (seems like the most random number ever). Here is the code that packages the files and sends them to the client: ... if ($filenames != "") { // Create temp zip file fwrite($log, "Generating unique zip filename... "); $tmp = tempnam("/birl/data/", "tempzip"); $tmp_zip = $tmp . ".zip"; fwrite($log, "[success]\n"); // We deliver a zip file header("Content-Type: archive/zip"); // The filename the client will see when downloading header("Content-Disposition: attachment; filename=bulk.zip"); // Zip the files into the tmp_zip file, note that we use very low // compression (1) to ensure rapid processing, and we get rid of paths (j), // so the zip contains only the files within those paths. fwrite($log, "Zipping files... "); $output = shell_exec("zip -0j $tmp_zip $filenames"); fwrite($log, "zip: "); fwrite($log, $output); fwrite($log, "[success]\n"); // Calc the length of the zip; needed for the progress bar of the browser $filesize = filesize($tmp_zip); header("Content-Length: $filesize"); // Keep a file pointer open, so we don't actually delete the file until the script is done $fp = fopen($tmp_zip, 'r'); // Clean up the tmp zip file fwrite($log, "Cleaning up... "); unlink($tmp); unlink($tmp_zip); fwrite($log, "[success]\n"); // Deliver the zip file fwrite($log, "Delivering to client... "); ob_clean(); flush(); fpassthru($fp); fwrite($log, "[success]\n"); } ... Note that if I comment out the calls to unlink and check the resulting .zip file, it is fully intact. So, it appears something goes wrong during the delivery process. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/269873-passthru-size-limit-zipping-on-the-fly/ Share on other sites More sharing options...
Christian F. Posted October 24, 2012 Share Posted October 24, 2012 I'd recommend adding a background operating to zip those files, and then use some sort of alert system to notify the user when it's done. That should help combat the timeouts, which I'm pretty sure is the problem, and you can turn the timeouts off only for the background process. Profiling the above script might help figuring out where the trouble lies, as it'll show you exactly how long every single piece of the script takes to run. Quote Link to comment https://forums.phpfreaks.com/topic/269873-passthru-size-limit-zipping-on-the-fly/#findComment-1387562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.