Hugely speed up startup
This commit is contained in:
parent
8d1f8c401e
commit
353f8b6281
@ -51,7 +51,7 @@ function configureCall($call) {
|
||||
$call->configuration['enable_AGC'] = false;
|
||||
$call->configuration['enable_AEC'] = false;
|
||||
$call->configuration['shared_config'] = [
|
||||
'audio_init_bitrate' => 500 * 1000,
|
||||
'audio_init_bitrate' => 100 * 1000,
|
||||
'audio_max_bitrate' => 500 * 1000,
|
||||
'audio_min_bitrate' => 100 * 1000,
|
||||
'audio_congestion_window' => 4*1024
|
||||
|
@ -47,18 +47,19 @@ class API extends APIFactory
|
||||
flock($realpaths['lockfile'], LOCK_UN);
|
||||
fclose($realpaths['lockfile']);
|
||||
}
|
||||
class_exists('\\Volatile');
|
||||
\danog\MadelineProto\Logger::class_exists();
|
||||
|
||||
try {
|
||||
$unserialized = unserialize($tounserialize);
|
||||
} catch (\danog\MadelineProto\Bug74586Exception $e) {
|
||||
class_exists('\\Volatile');
|
||||
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
||||
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
||||
class_exists('\\danog\\MadelineProto\\'.$class);
|
||||
}
|
||||
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
class_exists('\\Volatile');
|
||||
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
||||
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
||||
class_exists('\\danog\\MadelineProto\\'.$class);
|
||||
|
@ -35,8 +35,11 @@ class Logger
|
||||
public static $is_fork = false;
|
||||
public static $can_getmypid = true;
|
||||
public static $processed_fork = false;
|
||||
public static $ipv6;
|
||||
private static $pid;
|
||||
|
||||
public static $inited = false;
|
||||
|
||||
const ULTRA_VERBOSE = 5;
|
||||
const VERBOSE = 4;
|
||||
const NOTICE = 3;
|
||||
@ -46,9 +49,11 @@ class Logger
|
||||
|
||||
public static function class_exists()
|
||||
{
|
||||
if (!self::$inited) {
|
||||
self::$has_thread = class_exists('\\Thread') && method_exists('\\Thread', 'getCurrentThread');
|
||||
self::$BIG_ENDIAN = pack('L', 1) === pack('N', 1);
|
||||
self::$bigint = PHP_INT_SIZE < 8;
|
||||
self::$ipv6 = (bool) strlen(@file_get_contents('http://v6.ipv6-test.com/api/myip.php', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0;
|
||||
preg_match('/const V = (\\d+);/', @file_get_contents('https://raw.githubusercontent.com/danog/MadelineProto/master/src/danog/MadelineProto/MTProto.php'), $matches);
|
||||
if (isset($matches[1]) && \danog\MadelineProto\MTProto::V < (int) $matches[1]) {
|
||||
throw new \danog\MadelineProto\Exception(hex2bin(\danog\MadelineProto\Lang::$current_lang['v_error']), 0, null, 'MadelineProto', 1);
|
||||
@ -69,6 +74,8 @@ class Logger
|
||||
self::$isatty = defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
}
|
||||
self::$inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function is_fork()
|
||||
|
@ -111,6 +111,7 @@ class MTProto
|
||||
|
||||
public function __magic_construct($settings = [])
|
||||
{
|
||||
\danog\MadelineProto\Logger::class_exists();
|
||||
// Parse settings
|
||||
$this->parse_settings($settings);
|
||||
if (!defined('\\phpseclib\\Crypt\\Common\\SymmetricKey::MODE_IGE') || \phpseclib\Crypt\Common\SymmetricKey::MODE_IGE !== 6) {
|
||||
@ -120,7 +121,6 @@ class MTProto
|
||||
throw new Exception(['extension', 'xml']);
|
||||
}
|
||||
$this->emojis = json_decode(self::JSON_EMOJIS);
|
||||
\danog\MadelineProto\Logger::class_exists();
|
||||
// Connect to servers
|
||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['inst_dc'], Logger::ULTRA_VERBOSE);
|
||||
if (!isset($this->datacenter)) {
|
||||
@ -195,13 +195,11 @@ class MTProto
|
||||
}
|
||||
$this->altervista = isset($_SERVER['SERVER_ADMIN']) && strpos($_SERVER['SERVER_ADMIN'], 'altervista.org');
|
||||
|
||||
$this->settings['connection_settings']['all']['ipv6'] = (bool) strlen(@file_get_contents('http://ipv6.test-ipv6.com/', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0;
|
||||
$this->settings['connection_settings']['all']['ipv6'] = \danog\MadelineProto\Logger::$ipv6;
|
||||
/*if (isset($this->settings['pwr']['update_handler']) && $this->settings['pwr']['update_handler'] === $this->settings['updates']['callback']) {
|
||||
unset($this->settings['pwr']['update_handler']);
|
||||
$this->updates = [];
|
||||
}*/
|
||||
// decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
|
||||
preg_match('/const V = (\\d+);/', @file_get_contents('https://raw.githubusercontent.com/danog/MadelineProto/master/src/danog/MadelineProto/MTProto.php'), $matches);
|
||||
$keys = array_keys((array) get_object_vars($this));
|
||||
if (count($keys) !== count(array_unique($keys))) {
|
||||
throw new Bug74586Exception();
|
||||
@ -451,7 +449,7 @@ class MTProto
|
||||
// can be tcp_full, tcp_abridged, tcp_intermediate, http, https, obfuscated2, udp (unsupported)
|
||||
'test_mode' => false,
|
||||
// decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
|
||||
'ipv6' => (bool) strlen(@file_get_contents('http://ipv6.test-ipv6.com/', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0,
|
||||
'ipv6' => \danog\MadelineProto\Logger::$ipv6,
|
||||
// decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
|
||||
'timeout' => 2,
|
||||
// timeout for sockets
|
||||
|
@ -80,72 +80,4 @@ class Serialization
|
||||
|
||||
return $wrote;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deserialize API class.
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @throws \danog\MadelineProto\Exception
|
||||
*
|
||||
* @return API
|
||||
*/
|
||||
/*
|
||||
public static function deserialize($filename, $no_updates = false)
|
||||
{
|
||||
$realpaths = self::realpaths($filename);
|
||||
if (file_exists($realpaths['file'])) {
|
||||
if (!file_exists($realpaths['lockfile'])) {
|
||||
touch($realpaths['lockfile']);
|
||||
clearstatcache();
|
||||
}
|
||||
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r');
|
||||
\danog\MadelineProto\Logger::log('Waiting for shared lock of serialization lockfile...');
|
||||
flock($realpaths['lockfile'], LOCK_SH);
|
||||
\danog\MadelineProto\Logger::log('Lock acquired, deserializing');
|
||||
|
||||
try {
|
||||
$tounserialize = file_get_contents($realpaths['file']);
|
||||
} finally {
|
||||
flock($realpaths['lockfile'], LOCK_UN);
|
||||
fclose($realpaths['lockfile']);
|
||||
}
|
||||
\danog\MadelineProto\Logger::class_exists();
|
||||
|
||||
try {
|
||||
$unserialized = unserialize($tounserialize);
|
||||
} catch (\danog\MadelineProto\Bug74586Exception $e) {
|
||||
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized);
|
||||
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
||||
class_exists('\\danog\\MadelineProto\\'.$class);
|
||||
}
|
||||
class_exists('\\Volatile');
|
||||
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized);
|
||||
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
|
||||
class_exists('\\danog\\MadelineProto\\'.$class);
|
||||
}
|
||||
class_exists('\\Volatile');
|
||||
Logger::log((string) $e, Logger::ERROR);
|
||||
if (strpos($e->getMessage(), "Erroneous data format for unserializing 'phpseclib\\Math\\BigInteger'") === 0) {
|
||||
$tounserialize = str_replace('phpseclib\\Math\\BigInteger', 'phpseclib\\Math\\BigIntegor', $unserialized);
|
||||
}
|
||||
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
||||
}
|
||||
if ($unserialized instanceof \danog\PlaceHolder) {
|
||||
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
||||
}
|
||||
} else {
|
||||
throw new Exception(\danog\MadelineProto\Lang::$current_lang['file_not_exist']);
|
||||
}
|
||||
if ($unserialized === false) {
|
||||
throw new Exception(\danog\MadelineProto\Lang::$current_lang['deserialization_error']);
|
||||
}
|
||||
if ($unserialized instanceof \danog\MadelineProto\API) {
|
||||
$unserialized->session = $filename;
|
||||
}
|
||||
|
||||
return $unserialized;
|
||||
}*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user