简体   繁体   中英

Memory Management and ZipArchive class in PHP

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM