PHP Zip存档偶尔创建多个文件 [英] PHP Zip Archive sporadically creating multiple files

查看:77
本文介绍了PHP Zip存档偶尔创建多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本(在Apache 2.2上运行PHP 5.2),该脚本创建文件的zip存档供用户下载.一切似乎都正常.我唯一的问题是,在ZIP归档成功完成之前,将定期创建多个文件.示例:

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

archive-name.zip.a09600

archive-name.zip.a09600

archive-name.zip.b09600

archive-name.zip.b09600

archive-name.zip.c09600

archive-name.zip.c09600

这并非每次都发生;仅定期-该文件仍会创建,但有时这些多余的文件"在完成后会留在服务器上.创建ZIP存档的代码如下:

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

推荐答案

这实际上是与会话相关的问题;由于多次调用session_write_close()的代码中的一个更高级别的函数的调用(使用exec()解决已知错误的方法),因此会话数据不会在第一次通过时保存.问题在于会话之后再次开始备份之后,保存/检索数据.

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.

这篇关于PHP Zip存档偶尔创建多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆