|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-02-15 10:22 UTC] foster dot graeme at gmail dot com
Description: ------------ When adding files to an archive, (using successive ZipArchive::addFile() commands) the compression doesn't happen until the file is closed. This can result in an out of memory error, a temporary fix is to close the archive and then reopen it within the php code. An idea solution would be to compress the file when it is added, probably in function _zip_replace(), but I don't know what the implications of this would be. It would certainly require a rewrite of the ugly function zip_close(). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 16:00:02 2025 UTC |
"I still think that it would be nice if there was some way for the system to manage this." It is in the TODO list. As I said three times already in this discussion. The solution is to add different modes: - commit at the end when the archive is close - immediate addition (will be much slower) And again, it is in my TODOs already. I cannot tell when they will be available (I do it on my free time). In the meantime a simple: if (($zip->numFiles % $yourlimit) == 0) {close; reopen;} will do it. "the archive can be partially built prior to the ulimit being reached. This could be set as 250, with the ability to overload it. Maybe this would only be triggered if a flag was set when the archive was opened." This solution does not work.The limit is arbitrary. There is no way to get an exact value (and I doubt php is the only running process).Would it be possible to add a brief description of this situation to the documentation, for example the following could be added to the description of ZipArchive::addFile Description bool ZipArchive::addFile ( string filename [, string localname] ) Adds a link to the ZIP archive from a given path. When the archive is closed the link is checked to ensure that the file still exists and will then be compressed and added to the archive. If a lot of files are being added then the number of file handles permitted by the OS may be exceeded, if that occurs then the status will be set to ZIPARCHIVE::ER_OPEN. This can be avoided by closing the archive before the limit is reached and then reopening the archive. for example: if ($zip->numfile % $limit == 0) { $zip->close(); $zip->open($filename,ZIPARCHIVE::CREATE); }