Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better Compression of ZPK #9

Open
burkl opened this issue Sep 30, 2013 · 7 comments
Open

Better Compression of ZPK #9

burkl opened this issue Sep 30, 2013 · 7 comments

Comments

@burkl
Copy link
Contributor

burkl commented Sep 30, 2013

No description provided.

@slaff
Copy link
Contributor

slaff commented Oct 1, 2013

It seems that using the php zip extension does not allow setting of compression level. See this
https://bugs.php.net/bug.php?id=41243 for details. If there is another way to create Zip files on all OS where PHP 5.3 is running I and supports better compression, then I will be more then happy to make this change.

@zvikazend
Copy link
Contributor

add external binaries to the package - is it an option?
​Zvika​

On Tue, Oct 1, 2013 at 11:17 AM, slaff notifications@github.com wrote:

It seems that using the php zip extension does not allow setting of
compression level. See this
https://bugs.php.net/bug.php?id=41243 for details. If there is another
way to create Zip files on all OS where PHP 5.3 is running I and supports
better compression, then I will be more then happy to make this change.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-25432503
.

@slaff
Copy link
Contributor

slaff commented Oct 1, 2013

7zip is providing the best zip compression, as far as I know, and it would be great if there was binary in every major OS. Unfortunately that is not the case. What I can think of is to use the "zip" command under Linux/MacOS X if it is available and fallback to the PHP Zip extension if it is not. (The best will be to improve the PHP zip extension but that is way off the purpose of this project. ).

@zvikazend
Copy link
Contributor

Nice - 7zip has unofficial ports for all our supported systems, so we can
place it in the bin directory for each OS.
Also you can place in the ZS-SDK requirements additional section to install
distro available 7zip compressor and fallback to PHP as you plan if
unavailable.

Fixing PHP-ZIP can be nice, if its only implementing compression flags and
the functionality is there...
but it will not be part of PHP 5.3 anyway.

​Zvika​

On Tue, Oct 1, 2013 at 12:43 PM, slaff notifications@github.com wrote:

7zip is providing the best zip compression, as far as I know, and it would
be great if there was binary in every major OS. Unfortunately that is not
the case. What I can think of is to use the "zip" command under Linux/MacOS
X if it is available and fallback to the PHP Zip extension if it is not.
(The best will be to improve the PHP zip extension but that is way off the
purpose of this project. ).


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-25436774
.

@andigutmans
Copy link

I think looking for system zip and falling back is best option. Many installations also won't have ext/zip

Sent from my iPhone

On Oct 1, 2013, at 2:43 AM, slaff notifications@github.com wrote:

7zip is providing the best zip compression, as far as I know, and it would be great if there was binary in every major OS. Unfortunately that is not the case. What I can think of is to use the "zip" command under Linux/MacOS X if it is available and fallback to the PHP Zip extension if it is not. (The best will be to improve the PHP zip extension but that is way off the purpose of this project. ).


Reply to this email directly or view it on GitHub.

@clarkphp
Copy link
Contributor

Low priority, to be sure, but I think this is possible now. Am I looking at this correctly?
https://www.php.net/manual/en/zip.constants.php
php/php-src@3a55ea02

slaff pushed a commit that referenced this issue Sep 29, 2021
@slaff
Copy link
Contributor

slaff commented Sep 29, 2021

@clarkphp I've tried using different compression algorithms and compression levels. But strangely enough the length of the final zip file was always the same.

Here is my initial test script:

<?php
$zip = new ZipArchive;
$res = $zip->open('/tmp/test.zip', ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
if ($res === TRUE) {

    $files = [
        'x.php',
        'y.php',
        'z.php',
        // .. more files were used in actual tests....
    ];

    foreach($files as $file) {
        $zip->addFile(__DIR__ .'/data/'.$file, $file);
//        $result = $zip->setCompressionName($file, ZipArchive::CM_REDUCE_4); // same result as NOT setting the compression
//        $result = $zip->setCompressionName($file, ZipArchive::CM_DEFLATE); // <- did not work for me
//        $result = $zip->setCompressionName($file, ZipArchive::CM_BZIP2, 9); // same result as NOT setting the compression
        if($result) {
            die('Unable to set compression level!');
        }
    }

    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}

Using CM_REDUCE_4 or, CM_BZIP2 with compression 9 did't make even a single byte difference for the final test.zip file. I am using Zend Server's PHP 7.4.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants