zend-patterns / ZendServerSDK

Pure ZF2 CLI for zpk creation and webapi client.
BSD 3-Clause "New" or "Revised" License
22 stars 17 forks source link

Better Compression of ZPK #9

Open burkl opened 10 years ago

slaff commented 10 years ago

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 commented 10 years ago

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/zendtech/ZendServerSDK/issues/9#issuecomment-25432503 .

slaff commented 10 years ago

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 commented 10 years ago

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

andigutmans commented 10 years ago

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 commented 2 years ago

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

slaff commented 2 years ago

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