PHP Zip Archive sporadically creating multiple files
- by user516558
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 extra '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