ZendServerSDK icon indicating copy to clipboard operation
ZendServerSDK copied to clipboard

Better Compression of ZPK

Open burkl opened this issue 12 years ago • 7 comments

burkl avatar Sep 30 '13 14:09 burkl

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.

slaff avatar Oct 01 '13 08:10 slaff

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

On Tue, Oct 1, 2013 at 11:17 AM, slaff [email protected] 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/zendtech/ZendServerSDK/issues/9#issuecomment-25432503 .

zvikazend avatar Oct 01 '13 09:10 zvikazend

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. ).

slaff avatar Oct 01 '13 09:10 slaff

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 [email protected] 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/zendtech/ZendServerSDK/issues/9#issuecomment-25436774 .

zvikazend avatar Oct 01 '13 10:10 zvikazend

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 [email protected] 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.

andigutmans avatar Oct 01 '13 13:10 andigutmans

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 https://github.com/php/php-src/commit/3a55ea02

clarkphp avatar Sep 24 '21 22:09 clarkphp

@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.

slaff avatar Sep 29 '21 13:09 slaff