diff --git a/composer.json b/composer.json index e2562a58..2321926d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require": { "php": ">=7.1.0", - "danog/primemodule": "^1.0.3", + "danog/primemodule": "^1", "danog/magicalserializer": "^1.0", "phpseclib/phpseclib": "dev-master#27370df as 2.0.15", "vlucas/phpdotenv": "^3", diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 137e4249..b6ebf4b9 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -32,6 +32,7 @@ class API extends APIFactory public $getting_api_id = false; public $my_telegram_org_wrapper; public $asyncAPIPromise; + private $oldInstance = false; public function __magic_construct($params = [], $settings = []) { @@ -137,7 +138,7 @@ class API extends APIFactory if (isset($unserialized->API)) { $this->API = $unserialized->API; $this->APIFactory(); - $unserialized->donotlog = true; + $unserialized->oldInstance = true; $deferred->resolve(); yield $this->API->initAsync(); $this->APIFactory(); @@ -152,6 +153,15 @@ class API extends APIFactory } $params = $settings; } + if (!\danog\MadelineProto\Logger::$default) { + if (!isset($settings['logger']['logger_param'])) { + $settings['logger']['logger_param'] = Magic::$script_cwd.'/MadelineProto.log'; + } + if (!isset($settings['logger']['logger'])) { + $settings['logger']['logger'] = php_sapi_name() === 'cli' ? 3 : 2; + } + \danog\MadelineProto\Logger::constructor($settings['logger']['logger'], $settings['logger']['logger_param'], '', isset($settings['logger']['logger_level']) ? $settings['logger']['logger_level'] : Logger::VERBOSE, isset($settings['logger']['max_size']) ? $settings['logger']['max_size'] : 100 * 1024 * 1024); + } if (!isset($params['app_info']['api_id']) || !$params['app_info']['api_id']) { $app = yield $this->api_start_async($params); $params['app_info']['api_id'] = $app['api_id']; @@ -194,7 +204,7 @@ class API extends APIFactory if ($this->asyncInitPromise) { $this->init(); } - if (!isset($this->donotlog)) { + if (!$this->oldInstance) { if ($this->API) { $this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)'); $this->API->destructing = true; diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index fe7721e4..a8004bf0 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -254,6 +254,11 @@ class MTProto extends AsyncConstruct implements TLCallback return $this->datacenter->getHTTPClient(); } + public function getDNSClient() + { + return $this->datacenter->getDNSClient(); + } + public function fileGetContents($url): \Generator { return $this->datacenter->fileGetContents($url); diff --git a/src/danog/MadelineProto/Magic.php b/src/danog/MadelineProto/Magic.php index 48a73f15..48cee5db 100644 --- a/src/danog/MadelineProto/Magic.php +++ b/src/danog/MadelineProto/Magic.php @@ -157,7 +157,16 @@ class Magic ] ); resolver(new Rfc8484StubResolver($DohConfig)); - + if (php_sapi_name() !== 'cli') { + try { + error_reporting(E_ALL); + ini_set('log_errors', 1); + ini_set('error_log', Magic::$script_cwd.'/MadelineProto.log'); + error_log('Enabled PHP logging'); + } catch (\danog\MadelineProto\Exception $e) { + //$this->logger->logger('Could not enable PHP logging'); + } + } self::$inited = true; } }