PHP Zip Archive 偶尔创建多个文件
我有一个 PHP 脚本(在 Apache 2.2 上运行 PHP 5.2),它创建文件的 zip 存档供用户下载。一切似乎都运转良好;我遇到的唯一问题是,在 ZIP 存档成功完成之前,会定期创建多个文件。示例:
archive-name.zip
archive-name.zip.a09600
archive-name.zip.b09600
archive-name.zip.c09600
这并不是每次都会发生;仅定期 - 文件仍然会创建,但有时这些额外的“文件”在完成后会留在服务器上。创建 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明这实际上是一个与会话相关的问题;会话数据不会在第一次传递时保存,因为调用了代码中更高层的函数,该函数多次调用 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.