2

I need to create a large zip archive from jpg files. The zip generation breaks on 64MB - There is no way to increase the memory limit on the hoster.

I tried many methods to generate the zip files but all failed:

  • The PHP ZipArchive Class.
  • exec("zip -r file.zip *.jpg")
  • pclzip (with an option to generate temporary files instead of memory)

Maybe there is another way to create zip files using stream/tempprary files with low memory inpact?

Thanks for suggestions

MilMike
  • 11,759
  • 12
  • 58
  • 78
  • Have you read this post? It looks helpful and rather comprehensive. http://stackoverflow.com/questions/4357073/on-the-fly-zipping-streaming-of-large-files-in-php-or-otherwise – Nick Allen Oct 22 '14 at 07:31
  • @NickAllen Thanks, I tried fopen and it also didn't work. :( I think on the server there is also a limit on the machine itself, not only in php. – MilMike Oct 22 '14 at 08:11

1 Answers1

1

You can try set_time_limit ( sec ) or ini_set('max_execution_time', sec) in your script.

You can try something like this

initialise your zip class

foreach ( files in the directory as $idx => $name) {

    add $name to your zip file;

    // every 10 files zipped, reset the max_execution_time
    if ( $idx > 0 && $idx % 10 == 0 ) {
        set_time_limit ( 30 ); //if it doesnt work try to use ini_set('max_execution_time', 30);
    }
}

It will keep resetting the max_execution_time to 30 seconds every 10 files you zip.

I used 10 files as an example, you can set it depending upon your average file size.

Abhay Shukla
  • 33
  • 1
  • 7