哪个更有效率:使用系统命令压缩或使用PHP ZipArchive? [英] Which is More Efficient: Zipping With a System Command or Using PHP ZipArchive?
问题描述
我最近得到了一项任务,包括上载一个zip文件,将其作为博客存储在数据库中,然后在客户端请求时提取并呈现该zip文件的内容.
I've recently been given a task that involves uploading a zip file, storing it in a database as a blog, and then extracting and presenting the contents of that zip file when the client requests it.
对于此任务,我有两种方法:使用 exec
命令执行Web服务器所运行的Linux OS固有的 zip
命令.PHP附带的ZipArchive类.
I've got two approaches for this task: Using the exec
command to execute the zip
command native to the Linux OS the web server is running on, or using the ZipArchive class that comes with PHP.
- 哪种方法使用的内存最少?
- 哪种方法提供最大的灵活性?W
- 一种方法的主要优点是什么比其他?
推荐答案
exec('zip')
对于大型/许多文件而言,速度更快.内置例程总是较慢(由于许多库调用和开销.系统 zip
可能具有使用高度优化的例程的优势.作为 exec
方法,可以轻松地将输出格式从 zip
更改为 rar
或 7zip
或 bzip
等.
exec('zip')
is way faster for large/many files. The built-in routines are always slower(due to many library calls & overhead. The system zip
may have the advantage of using highly optimized routines. As a plus to the exec
method, is the ease to change output formats from zip
to rar
, or 7zip
or bzip
etc...
这篇关于哪个更有效率:使用系统命令压缩或使用PHP ZipArchive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!