kjdev / php-ext-brotli

Brotli Extension for PHP
MIT License
172 stars 29 forks source link

Quality param has no effect #40

Closed mattschlosser closed 1 year ago

mattschlosser commented 2 years ago

After installing the extension, when using brotli_compress to compress a large text file, the quality level param does not seem to effect compression. Every file output is exactly the same size.

<?php
$file = file_get_contents("some_big_text_file.txt"); // file is 386795 bytes
$compressed = brotli_compress($file, 1); 
$size = mb_strlen($compressed, '8bit'); // file is 30131 bytes

$compressed = brotli_compress($file, 2); 
$size = mb_strlen($compressed, '8bit'); // file is 30131 bytes

// ...etc 

$compressed = brotli_compress($file, 11); 
$size = mb_strlen($compressed, '8bit'); // file is 30131 bytes

I was trying to reduce the level as it seems to default to the highest, which also is slowest.

Thanks

some_big_text_file.txt

kjdev commented 1 year ago

In my environment, the compression size seems to change depending on the parameter. Please let us know the details of your environment.

<?php
// t.php

$file = file_get_contents("some_big_text_file.txt"); // file is 386795 bytes
$size = mb_strlen($file, '8bit');
echo "${size} bytes\n";

$compressed = brotli_compress($file, 1);
$size = mb_strlen($compressed, '8bit');
echo "${size} bytes\n";

$compressed = brotli_compress($file, 2);
$size = mb_strlen($compressed, '8bit');
echo "${size} bytes\n";

$compressed = brotli_compress($file, 11);
$size = mb_strlen($compressed, '8bit');
echo "${size} bytes\n";
$ php -v
PHP 8.1.10 (cli) (built: Aug 30 2022 16:09:36) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
$ php t.php
386795 bytes
70466 bytes
72338 bytes
30131 bytes
nono303 commented 1 year ago

Fyi, done the test (on windows) and sounds good:

S:\>php t.php
448792 bytes
61154 bytes
57619 bytes
38076 bytes

S:\>php -v
PHP 8.1.11 (cli) (built: Sep 30 2022 15:33:11) (NTS MSVC 19.34.31823.3, untested x64)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.11, Copyright (c), by Zend Technologies

using php-ext-brotli 0.13.1- git commit:c172976 brotli 1.0.9 - git commit:e61745a

mattschlosser commented 1 year ago

After trying again, I found the error was because of a mistake on my end.

Sorry to bother