Detect enabled Brotli compression before Gzip compression

This commit is contained in:
djmaze 2021-09-27 12:50:59 +02:00
parent 244d4c49c5
commit 2d4ce14b1c
2 changed files with 8 additions and 5 deletions

View file

@ -4,9 +4,12 @@
//header('Strict-Transport-Security: max-age=31536000');
// Uncomment to use gzip encoded output
// Uncomment to use gzip compressed output
//define('USE_GZIP', 1);
// Uncomment to use brotli compressed output
//define('USE_BROTLI', 1);
// Uncomment to enable multiple domain installation.
//define('MULTIDOMAIN', 1);

View file

@ -84,7 +84,7 @@
if (!is_dir(APP_DATA_FOLDER_PATH))
{
mkdir(APP_DATA_FOLDER_PATH, 0700);
mkdir(APP_DATA_FOLDER_PATH, 0700, true);
}
else
{
@ -239,9 +239,7 @@
// See https://github.com/kjdev/php-ext-brotli
if (!ini_get('zlib.output_compression') && !ini_get('brotli.output_compression')) {
if (defined('USE_GZIP')) {
ob_start('ob_gzhandler');
} else if (defined('USE_BROTLI') && is_callable('brotli_compress_add') && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br')) {
if (defined('USE_BROTLI') && is_callable('brotli_compress_add') && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br')) {
ob_start(function(string $buffer, int $phase){
static $resource;
if ($phase & PHP_OUTPUT_HANDLER_START) {
@ -250,6 +248,8 @@
}
return brotli_compress_add($resource, $buffer, ($phase & PHP_OUTPUT_HANDLER_FINAL) ? BROTLI_FINISH : BROTLI_PROCESS);
});
} else if (defined('USE_GZIP')) {
ob_start('ob_gzhandler');
}
}