Implemented GZIP compression for methods

This commit is contained in:
Daniil Gentili 2017-09-26 14:41:53 +02:00
parent 777870a67b
commit 801934775c
2 changed files with 7 additions and 1 deletions

View File

@ -74,7 +74,12 @@ trait CallHandler
if (isset($queue)) {
$serialized = $this->serialize_method('invokeAfterMsgs', ['msg_ids' => $this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue], 'query' => $serialized]);
}
$l = strlen($serialized);
$g = strlen($gzipped = gzencode($serialized));
if ($l > 500 && $g < $l) {
\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);
$serialized = $this->serialize_object(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
}
$last_recv = $this->last_recv;
if ($canunset = !$this->updates_state['sync_loading'] && !$this->threads && !$this->run_workers) {
$this->updates_state['sync_loading'] = true;

View File

@ -76,6 +76,7 @@ class Serialization
} catch (\danog\MadelineProto\Bug74586Exception $e) {
$unserialized = \danog\Serialization::unserialize($tounserialize);
} catch (\danog\MadelineProto\Exception $e) {
if (Logger::$constructed) Logger::log([(string) $e], Logger::ERROR);
$unserialized = \danog\Serialization::unserialize($tounserialize);
}
if ($unserialized instanceof \danog\PlaceHolder) {