Ben bu gibi bir kod ile PHP ile bir 14MB arşivi açın çalışıyorum:
$zip = zip_open("c:\kosmas.zip");
while ($zip_entry = zip_read($zip)) {
$fp = fopen("c:/unzip/import.xml", "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
break;
}
zip_close($zip);
}
Bu klasik "Allowed memory size of blablabla bytes exhausted" ile 128MB bellek sınırı ile benim localhost üzerinde başarısız olur. Sunucuda, ben bu sınırın içine sığabilir bunu yapmak için daha iyi bir yolu var, 16MB sınırı var? Bu fazla bellek 128MB tahsis var neden görmüyorum. Şimdiden teşekkürler.
Solution: I started reading the files in 10Kb chunks, problem solved with peak memory usage arnoud 1.5MB.
$filename = 'c:\kosmas.zip';
$archive = zip_open($filename);
while($entry = zip_read($archive)){
$size = zip_entry_filesize($entry);
$name = zip_entry_name($entry);
$unzipped = fopen('c:/unzip/'.$name,'wb');
while($size > 0){
$chunkSize = ($size > 10240) ? 10240 : $size;
$size -= $chunkSize;
$chunk = zip_entry_read($entry, $chunkSize);
if($chunk !== false) fwrite($unzipped, $chunk);
}
fclose($unzipped);
}