mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 09:58:59 +01:00
Improve management of connections and server errors
This commit is contained in:
parent
d547164e7c
commit
afb15deb9e
@ -47,7 +47,7 @@ class Connection
|
|||||||
public $object_queue = [];
|
public $object_queue = [];
|
||||||
public $ack_queue = [];
|
public $ack_queue = [];
|
||||||
public $i = [];
|
public $i = [];
|
||||||
private $must_open = false;
|
public $must_open = false;
|
||||||
|
|
||||||
public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6)
|
public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6)
|
||||||
{
|
{
|
||||||
@ -330,8 +330,8 @@ class Connection
|
|||||||
throw new Exception($response['description'], $response['code']);
|
throw new Exception($response['description'], $response['code']);
|
||||||
}
|
}
|
||||||
$close = $response['protocol'] === 'HTTP/1.0';
|
$close = $response['protocol'] === 'HTTP/1.0';
|
||||||
if (isset($headers['connection'])) {
|
if (isset($response['headers']['connection'])) {
|
||||||
$close = $headers['connection'] === 'close';
|
$close = strtolower($response['headers']['connection']) === 'close';
|
||||||
}
|
}
|
||||||
if ($close) {
|
if ($close) {
|
||||||
$this->close_and_reopen();
|
$this->close_and_reopen();
|
||||||
|
@ -70,6 +70,13 @@ trait MessageHandler
|
|||||||
*/
|
*/
|
||||||
public function recv_message($datacenter)
|
public function recv_message($datacenter)
|
||||||
{
|
{
|
||||||
|
if ($this->datacenter->sockets[$datacenter]->must_open) {
|
||||||
|
if ($this->is_http($datacenter)) {
|
||||||
|
$this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]);
|
||||||
|
} else {
|
||||||
|
$this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]);
|
||||||
|
}
|
||||||
|
}
|
||||||
$payload = $this->datacenter->sockets[$datacenter]->read_message();
|
$payload = $this->datacenter->sockets[$datacenter]->read_message();
|
||||||
if (strlen($payload) === 4) {
|
if (strlen($payload) === 4) {
|
||||||
return $this->unpack_signed_int($payload);
|
return $this->unpack_signed_int($payload);
|
||||||
|
@ -311,6 +311,8 @@ trait ResponseHandler
|
|||||||
throw new \danog\MadelineProto\PTSException($server_answer['error_message']);
|
throw new \danog\MadelineProto\PTSException($server_answer['error_message']);
|
||||||
}
|
}
|
||||||
switch ($server_answer['error_code']) {
|
switch ($server_answer['error_code']) {
|
||||||
|
case 500:
|
||||||
|
throw new \danog\MadelineProto\Exception('Re-executing query after server error...');
|
||||||
case 303:
|
case 303:
|
||||||
$this->datacenter->curdc = $aargs['datacenter'] = (int) preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
|
$this->datacenter->curdc = $aargs['datacenter'] = (int) preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
|
||||||
|
|
||||||
@ -359,8 +361,7 @@ trait ResponseHandler
|
|||||||
|
|
||||||
throw new \danog\MadelineProto\Exception('Re-executing query...');
|
throw new \danog\MadelineProto\Exception('Re-executing query...');
|
||||||
}
|
}
|
||||||
case 500:
|
|
||||||
throw new \danog\MadelineProto\Exception('Re-executing query after server error...');
|
|
||||||
default:
|
default:
|
||||||
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
|
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user