在即时高速生成ZIP文件,PHP + Apache的? [英] Generating ZIP files with PHP + Apache on-the-fly in high speed?

查看:152
本文介绍了在即时高速生成ZIP文件,PHP + Apache的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要引用一些著名的话的:

程序员常...投靠可以理解的,但灾难性的,对倾向在其工作的复杂性和独创性。故宫设计比任何一个程序时,他们通过制作程序复杂足以挑战其职业技能做出回应。

"Programmers… often take refuge in an understandable, but disastrous, inclination towards complexity and ingenuity in their work. Forbidden to design anything larger than a program, they respond by making that program intricate enough to challenge their professional skill."

在解决在工作中的一些问题,世俗我想出了这个主意,我不太清楚如何解决。我知道我不会实施这个,但我作为最好的解决办法是什么非常好奇。 :)

While solving some mundane problem at work I came up with this idea, which I'm not quite sure how to solve. I know I won't be implementing this, but I'm very curious as to what the best solution is. :)


假设你有这个大集合,JPG文件和一些奇怪的SWF文件。随着大我的意思是一对夫妇一千。每一个JPG文件的大小约为200KB,而主权财富基金可以达到的大小几MB。每天有一些新的JPG文件。因此,所有的东西总规模大约是1 GB,并且正在缓慢但稳步地增长。文件非常很少更改或删除。

Suppose you have this big collection with JPG files and a few odd SWF files. With "big" I mean "a couple thousand". Every JPG file is around 200KB, and the SWFs can be up to a few MB in size. Every day there's a few new JPG files. The total size of all the stuff is thus around 1 GB, and is slowly but steadily increasing. Files are VERY rarely changed or deleted.

用户可以查看每个文件个别地在网页上。不过也有希望,让他们一次下载一大堆人。文件附加有(日期,类别等),用户可以通过过滤收集的一些元数据。

The users can view each of the files individually on the webpage. However there is also the wish to allow them to download a whole bunch of them at once. The files have some metadata attached to them (date, category, etc.) that the user can filter the collection by.

最终执行将随后是允许用户指定某些过滤条件,然后下载相应的文件作为一个单一的ZIP文件。

The ultimate implementation would then be to allow the user to specify some filter criteria and then download the corresponding files as a single ZIP file.

由于标准的量足够大,我不能pre-生成所有可能的ZIP文件,而且必须做的即时。另一个问题是,在下载可以是相当大的,并用于与低速连接的用户也很可能会需要一个小时或更长时间。因此,对恢复的支持是一个必须具备的。

Since the amount of criteria is big enough, I cannot pre-generate all the possible ZIP files and must do it on-the-fly. Another problem is that the download can be quite large and for users with slow connections it's quite likely that it will take an hour or more. Support for "resume" is therefore a must-have.

在光明的一面,不过ZIP不需要COM preSS什么 - 这些文件大多是JPEG文件反正。因此,整个过程不应该比简单的文件下载更多的CPU密集型

On the bright side however the ZIP doesn't need to compress anything - the files are mostly JPEGs anyway. Thus the whole process shouldn't be more CPU-intensive than a simple file download.

该问题,那么,我已经确定因此:

The problems then that I have identified are thus:


  • PHP有脚本执行超时。虽然它可以通过脚本本身的改变,会有完全删除它没有问题?

  • 使用恢复选项时,过滤结果改不同的HTTP请求的可能性。这可以通过按时间顺序排序的结果,作为收集仅变得更大来减轻。然后请求URL会还包括,当它在最初创建和脚本不会考虑比年纪文件的日期。这将是足够的?

  • 将通过大量的文件数据通过PHP不影响性能本身?

你将如何实现这一点? PHP是到所有任务?



补充:

How would you implement this? Is PHP up to the task at all?


Added:

现在两个人都建议请求的ZIP文件存储在临时文件夹,并从那里为他们服务像往常一样的文件。虽然这确实是一个明显的解决方案,也有一些实际考虑,这些考虑使得该不可行

By now two people have suggested to store the requested ZIP files in a temporary folder and serving them from there as usual files. While this is indeed an obvious solution, there are several practical considerations which make this infeasible.

的zip文件通常是pretty大,少则数几十兆到百兆hundreads。这也是完全正常的用户请求一切,这意味着该文件将被大小超过千兆字节。也有许多可能的过滤器的组合,其中许多人都可能由用户选择的

The ZIP files will usually be pretty large, ranging from a few tens of megabytes to hundreads of megabytes. It's also completely normal for a user to request "everything", meaning that the ZIP file will be over a gigabyte in size. Also there are many possible filter combinations and many of them are likely to be selected by the users.

其结果是,将ZIP文件将pretty慢,以产生(由于数据和磁盘速度的绝对量),并且将在包含整个集合许多倍。我没有看到这个解决方案将如何没有一些大型昂贵的SCSI RAID阵列工作。

As a result, the ZIP files will be pretty slow to generate (due to sheer volume of data and disk speed), and will contain the whole collection many times over. I don't see how this solution would work without some mega-expensive SCSI RAID array.

推荐答案

这可能是你所需要的:
<一href=\"http://pablotron.org/software/zipstream-php/\">http://pablotron.org/software/zipstream-php/

这lib中,您可以建立一个动态流zip文件没有交换到磁盘。

This lib allows you to build a dynamic streaming zip file without swapping to disk.

这篇关于在即时高速生成ZIP文件,PHP + Apache的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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