Closed mattschlosser closed 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
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
After trying again, I found the error was because of a mistake on my end.
Sorry to bother
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.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