开发者

Memory Management and ZipArchive class in PHP

I have a PHP script that uses 开发者_Go百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜