views:

238

answers:

1

I have a PHP script that uses adds a lot of small files into the same zip arhchive file using PHP's ZipArchive class.

Recently script started to run out of memory, although the archive is large, but I add only small files one by one, safely re-opening archive each time I need to add a file.

The initial archive file grew little by little to 50 mb so I assume adding little files is not a problem, the real problem might be that whenever ZipArchive class adds a file, it unpacks the whole archive into memory. Is this correct assumption, can it be so?

+1  A: 

Memory management isn't one of PHP's strong points. I don't see anything in the manual to confirm or dispel the idea that the entire archive is unpacked into memory, but I'd guess that it is.

Try comparing the return value of $zip->open() to ZIPARCHIVE::ER_MEMORY - if they're equal, that should confirm that PHP is opening the entire archive in memory.

Another way to confirm it would be to compare the setting of memory_limit (http://us2.php.net/manual/en/ini.core.php#ini.memory-limit) to the size of the zip file.

bradym