1

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.

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.

  • Which approach uses the least amount of memory?
  • Which approach offers the most flexibility? W
  • What are the major advantages of one approach over the other?
Levi Hackwith
  • 9,232
  • 18
  • 64
  • 115
  • 1
    I didn't test it, so it's not a "proper" answer, but I would say that ``exec()`` is slower at small zip files since you'll need to start a new process (== lots of overhead). On large files it *may* be faster or slower depending on the efficiency of the algorithms used by the different implementations. the only way to figure this out is to test it, which should be fairly easy. – Martin Tournoij Aug 16 '11 at 14:22
  • I know for a fact that the PHP zip functions tend not to work with large files...as for starting a new process and the overhead :) ... if we still had pentium2 maybe...i'd say go with zip from command line if you can.. – Catalin Aug 16 '11 at 14:37
  • As I was saying :) http://stackoverflow.com/questions/5745255/php-aborting-when-creating-large-zip-file – Catalin Aug 16 '11 at 14:38

1 Answers1

2

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...

Community
  • 1
  • 1
Quamis
  • 10,924
  • 12
  • 50
  • 66