简体   繁体   English

PHP Zip存档偶尔创建多个文件

[英]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. 我有一个PHP脚本(在Apache 2.2上运行PHP 5.2),该脚本创建文件的zip存档供用户下载。 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. 我唯一的问题是,在ZIP归档成功完成之前,将定期创建多个文件。 Example: 例:

archive-name.zip 存档名称.zip

archive-name.zip.a09600 archive-name.zip.a09600

archive-name.zip.b09600 archive-name.zip.b09600

archive-name.zip.c09600 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存档的代码如下:

        $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() ). 由于多次调用session_write_close()的代码中的一个更高级别的函数的调用(使用exec()解决已知错误的方法),因此会话数据不会在第一次通过时保存。 The problem was in preserving/retrieving the data after the session started back up again after that. 问题在于会话之后再次开始备份之后,保留/检索数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM