PHP Zip Archive sporadically creating multiple files

这一生的挚爱 提交于 2019-12-08 09:46:14

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/4661914/php-zip-archive-sporadically-creating-multiple-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!