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

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

问题描述

我有一个 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:

档案名称.zip

档案名称.zip.a09600

archive-name.zip.a09600

档案名称.zip.b09600

archive-name.zip.b09600

档案名称.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 Archive 偶尔会创建多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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