Added option to change gzip compression threshold or disable it altogether

This commit is contained in:
Daniil Gentili 2017-10-04 20:40:49 +03:00
parent de26dc37ab
commit cab1bececc
2 changed files with 5 additions and 2 deletions

View File

@ -46,7 +46,7 @@ class MTProto
/*
const V = 71;
*/
const V = 73;
const V = 74;
const NOT_LOGGED_IN = 0;
const WAITING_CODE = 1;
@ -580,6 +580,9 @@ class MTProto
'peer' => [
'full_info_cache_time' => 60,
],
'requests' => [
'gzip_encode_if_gt' => 500 // Should I try using gzip encoding for requests bigger than N bytes? Set to -1 to disable.
],
'updates' => [
'handle_updates' => true, // Should I handle updates?
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter

View File

@ -74,7 +74,7 @@ trait CallHandler
if (isset($queue)) {
$serialized = $this->serialize_method('invokeAfterMsgs', ['msg_ids' => $this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue], 'query' => $serialized]);
}
if (($l = strlen($serialized)) > 500 && ($g = strlen($gzipped = gzencode($serialized))) < $l) {
if ($this->settings['requests']['gzip_encode_if_gt'] !== -1 && ($l = strlen($serialized)) > $this->settings['requests']['gzip_encode_if_gt'] && ($g = strlen($gzipped = gzencode($serialized))) < $l) {
$serialized = $this->serialize_object(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
\danog\MadelineProto\Logger::log(['Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.($g * 100 / $l).'%'], \danog\MadelineProto\Logger::VERBOSE);
}