diff --git a/src/Socket.php b/src/Socket.php index 18d9d30d..e72cf3a7 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -132,6 +132,7 @@ if (!extension_loaded('pthreads')) { public function __destruct() { socket_close($this->sock); + unset($this->sock); } public function setOption(int $level, int $name, $value) diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index ed6f695c..5cb643ae 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -194,6 +194,7 @@ class Connection public function close_and_reopen() { $this->__destruct(); + \danog\MadelineProto\Logger::log(['Reopening...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); $this->must_open = true; } @@ -214,10 +215,6 @@ class Connection public function write($what, $length = null) { - if ($this->must_open) { - $this->__construct($this->proxy, $this->extra, $this->ip, $this->port, $this->protocol, $this->timeout, $this->ipv6); - $this->must_open = false; - } if ($length !== null) { $what = substr($what, 0, $length); } else { @@ -260,11 +257,7 @@ class Connection throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']); } } - if (strlen($packet) !== $length) { - $this->close_and_reopen(); - throw new Exception(sprintf(\danog\MadelineProto\Lang::$current_lang['wrong_length_read'], $length, strlen($packet))); - } return @$this->obfuscated['decryption']->encrypt($packet); case 'tcp_abridged': @@ -279,11 +272,6 @@ class Connection throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']); } } - if (strlen($packet) !== $length) { - $this->close_and_reopen(); - - throw new Exception(sprintf(\danog\MadelineProto\Lang::$current_lang['wrong_length_read'], $length, strlen($packet))); - } return $packet; case 'udp': @@ -342,6 +330,10 @@ class Connection public function send_message($message) { + if ($this->must_open) { + $this->__construct($this->proxy, $this->extra, $this->ip, $this->port, $this->protocol, $this->timeout, $this->ipv6); + $this->must_open = false; + } switch ($this->protocol) { case 'tcp_full': $this->out_seq_no++; diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index a3805111..71193698 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -185,7 +185,7 @@ trait CallHandler } catch (\danog\MadelineProto\NothingInTheSocketException $e) { $last_error = 'Nothing in the socket'; \danog\MadelineProto\Logger::log(['An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...'], \danog\MadelineProto\Logger::WARNING); - continue 2; + continue;//2; } } if ($canunset) { diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 74ebe309..a7c4ee6b 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -205,7 +205,7 @@ trait PeerHandler if (isset($this->chats[$id])) { return $this->gen_all($this->chats[$id]); } - if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) { + if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true && $recursive) { $dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true); if (isset($dbres['ok']) && $dbres['ok']) { $this->resolve_username('@'.$dbres['result']);