PHP Zip Archive sporadically creating multiple files
I have a PHP script (running PHP 5.2 on Apache 2.2) that creates a zip archive of files for a user to download. Everything seems to work just fine; the only issue I have is that periodically multiple files will be created before the ZIP archive is successfully finished. Example:
archive-name.zip
archive-name.zip.a09600
archive-name.zip.b09600
archive-name.zip.c09600
This does not happen every single time; only periodically - the file is still created but sometimes these extr开发者_运维问答a 'files' are left on the server after it finishes. The code that creates the ZIP archive is as follows:
$zip_archive = new ZipArchive();
$zip_archive->open($archiveFullName,ZIPARCHIVE::CREATE);
if(!file_exists($archiveFullName)) {
foreach ($completed_file_arr as $zip_file) {
$isFiller = substr($zip_file,-8) == "_err.txt";
if(!$isFiller) {
$zip_archive->addFile($zip_file,$localname);
} else $zip_archive->addFromString ($zip_file, "The requested source file could not be found.");
}
}
while(!$zip_archive->close()) sleep(1); //ensure that the ZIP file finishes closing
This turned out to actually be a session related problem; the session data isn't being saved on the first pass because of calls to a function higher up in the code that calls session_write_close() several times (workaround to a known bug with exec() ). The problem was in preserving/retrieving the data after the session started back up again after that.
精彩评论