Best way to create large archives using PHP

Posted on 2011-05-02
Last Modified: 2012-05-11

We're developing a simple system to tar.gz or zip large media files (10 to 200mb each) into 1GB segments with a set of files. From basic research we found zip ( is one option as exec command is disabled on our server. Although our server is not equipped with zip pecl extension, we can request our hosting company to install it. Is this the best way? Or can you expert guys suggest better alternatives?

Thanks in advance.
Question by:harvest-soft
    LVL 16

    Accepted Solution

    Php has several pre-compiled archiving utilities.

    The zlib library is for use with gzip (.gz) files
    LVL 5

    Expert Comment

    This will Allow you to zip a folder to the folders name while adding a log, when u get exec working.

          exec("zip -vr foldername zipname >> log.txt");
          echo "complete";

    Author Comment

    For now, exec is ruled out for security reasons. Will have to decide between zip pecl extension and other better options if any.

    Author Comment

    MunterMan, isn't this same as zip pecl?
    LVL 16

    Expert Comment

    by:Chris Harte
    The zlib link I posted should work without having to install anything from pecl or making any changes to php.ini.

    Author Comment

    I am not sure how zlib could help zip multiple files.
    LVL 33

    Assisted Solution

    greetings harvest-soft, , The different "archives" packages available for PHP can be mis-understood, or confusing.
    The PHP  Zlib and Bzip2 packages do compression on a Single data segment (string, or file) - - so you will need to combine many different files into a single file or string to use these, there are some classes available (PHP TAR classes) to do file combining, but it's an extra hassle.
    The PHP Zip package would be better suited to your needs, since It can do many files and-or folders in a single Zip file, without addon packages or methods.

    the PECL packages, are use to install methods and functions after the PHP is up and operating, It seems that the PECL Zip package, installs the PHP Zip (, if the PHP Zip is not already installed, , I believe that the default PHP installation and setup auto installs the Zip package, you can run the PHP  phpinfo ( );  function to see what packages you have on your server   OR  - just run this code line below -

    $zip = new ZipArchive();

    if you do not get an error message about "Class Not Found" then you have the PHP Zip ready to use, and you can get PHP code to use from the manual at -

    I hope this gives you some information that helps, ask questions, if you need better explanation

    Author Comment


    I've already checked the phpinfo and I know Zip wasn't installed. It's PHP 5.2.1
    I basically wanted expert advice on what the most "production" suitable way to zip large media files. zlib is not going to help and I knew it. Anyways thanks guys.


    Author Closing Comment

    Overall good. But needed expert voice.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now