开发者

Dynamically creating large zip's for client downloads

There is a project where each user gets to download a zip containing around 2GB of data...

The only problem- is that there are a couple very small files which must change in this zip per-user.

Is there a开发者_如何学编程n elegant way to solve this, asides from not requiring it all be in the zip? Ideas I've considered:

1) Pushing pending orders onto a queue, and processing that queue when resources are available... processing will mean creating a new zip for each order, and then deleting it after N days

2) Manipulating the zip live in PHP somehow, before sending via a raw sort of push (i.e. spitting out the header, and then generating the data based on the files + custom files)

Any ideas for best-approach or memory issues I might encounter? Thanks!


The ZIP file structure is basically:

  1. Magic header, identifying the file as a ZIP archive.
  2. All of the file data, concatenated together. (The individual files can be optionally compressed.)
  3. Archive directory, containing file metadata (names, sizes, etc.) as well as the offset to the file data.

This means that you should be able to construct and output the ZIP archive on-the-fly, requiring only the directory data to be retained in memory, until you can write it out at the end. The ZIP archive itself will never need to exist on disk.

If you use this approach, there will be no concurrency issues in offering the ZIP file to multiple clients at once, and you won't have to use any disk space when constructing the archive.


imho

you can consider two zip file approach

  1. first zip will contains all of the common files, and make it as static file for download (However, transfer Gb is not reliable over http, you can suggest user to use scp, ftp or any client program that allow continuing download)
  2. second zip (php script) should contain a couple very small files which specify to user only, in this case, you can have minimum overhead over memory/disk space


Have you looked at PHP's zip extension? http://php.net/zip

From what I've seen you can manipulate ZIP archives on the fly in an OOP manner. I'm just not sure about the performance, it could be that 2GB zips can take some time to manipulate but you would have to try this yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜