Stuffs
This commit is contained in:
parent
c451471f78
commit
53bf8176f5
@ -215,7 +215,13 @@ class Connection
|
||||
$this->disconnect();
|
||||
yield $this->API->datacenter->dcConnectAsync($this->ctx->getDc());
|
||||
if ($this->API->hasAllAuth() && !$this->hasPendingCalls()) {
|
||||
$this->callFork($this->API->method_call_async_read('ping', ['ping_id' => $this->random_int()], ['datacenter' => $this->datacenter]));
|
||||
$this->callFork((function () {
|
||||
try {
|
||||
$this->API->method_call_async_read('ping', ['ping_id' => $this->random_int()], ['datacenter' => $this->datacenter]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->API->logger("Got an error while pinging on reconnect: $e", Logger::FATAL_ERROR);
|
||||
}
|
||||
})());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,8 @@ class Logger
|
||||
{
|
||||
if (!is_null(self::$default)) {
|
||||
self::$default->logger($param, $level, basename(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]['file'], '.php'));
|
||||
} else {
|
||||
echo $param.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class ReadLoop extends SignalLoop
|
||||
while (true) {
|
||||
try {
|
||||
$error = yield $this->waitSignal($this->readMessage());
|
||||
} catch (NothingInTheSocketException | StreamException | PendingReadError $e) {
|
||||
} catch (NothingInTheSocketException | StreamException | PendingReadError | \Error $e) {
|
||||
if (isset($connection->old)) {
|
||||
return;
|
||||
}
|
||||
|
@ -302,7 +302,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
public function __wakeup_async($backtrace)
|
||||
{
|
||||
set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
|
||||
set_exception_handler(['\\danog\\MadelineProto\\Serialization', 'serialize_all']);
|
||||
$this->setup_logger();
|
||||
if (\danog\MadelineProto\Magic::$has_thread && is_object(\Thread::getCurrentThread())) {
|
||||
return;
|
||||
|
@ -66,7 +66,7 @@ class Magic
|
||||
public static function class_exists()
|
||||
{
|
||||
set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
|
||||
//set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
|
||||
set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
|
||||
if (!self::$inited) {
|
||||
self::$has_thread = class_exists('\\Thread') && method_exists('\\Thread', 'getCurrentThread');
|
||||
self::$BIG_ENDIAN = pack('L', 1) === pack('N', 1);
|
||||
|
@ -87,7 +87,7 @@ class RPCErrorException extends \Exception
|
||||
|| !isset(self::$descriptions[$error])
|
||||
|| $code === 500
|
||||
) {
|
||||
$res = json_decode(@file_get_contents('https://rpc.pwrtelegram.xyz/?method='.$this->caller.'&code='.$this->code.'&error='.$this->rpc), true);
|
||||
$res = json_decode(@file_get_contents('https://rpc.pwrtelegram.xyz/?method='.$method.'&code='.$code.'&error='.$error), true);
|
||||
if (isset($res['ok']) && $res['ok']) {
|
||||
$description = $res['result'];
|
||||
|
||||
|
@ -24,11 +24,6 @@ namespace danog\MadelineProto;
|
||||
*/
|
||||
class Serialization
|
||||
{
|
||||
public static function serialize_all($exception)
|
||||
{
|
||||
echo $exception.PHP_EOL;
|
||||
}
|
||||
|
||||
public static function realpaths($file)
|
||||
{
|
||||
$file = Absolute::absolute($file);
|
||||
|
@ -1050,17 +1050,20 @@ invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X;
|
||||
auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode;
|
||||
auth.signUp#1b067634 phone_number:string phone_code_hash:string phone_code:string first_name:string last_name:string = auth.Authorization;
|
||||
auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization;
|
||||
auth.resendCode#3ef1a9bf phone_number:string phone_code_hash:string = auth.SentCode;
|
||||
auth.cancelCode#1f040578 phone_number:string phone_code_hash:string = Bool;
|
||||
|
||||
auth.logOut#5717da40 = Bool;
|
||||
|
||||
auth.resetAuthorizations#9fab0d1a = Bool;
|
||||
auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization;
|
||||
auth.importAuthorization#e3ef9613 id:int bytes:bytes = auth.Authorization;
|
||||
|
||||
auth.bindTempAuthKey#cdd42a05 perm_auth_key_id:long nonce:long expires_at:int encrypted_message:bytes = Bool;
|
||||
auth.importBotAuthorization#67a3ff2c flags:int api_id:int api_hash:string bot_auth_token:string = auth.Authorization;
|
||||
auth.checkPassword#d18b4d16 password:InputCheckPasswordSRP = auth.Authorization;
|
||||
auth.requestPasswordRecovery#d897bc66 = auth.PasswordRecovery;
|
||||
auth.recoverPassword#4ea56e92 code:string = auth.Authorization;
|
||||
auth.resendCode#3ef1a9bf phone_number:string phone_code_hash:string = auth.SentCode;
|
||||
auth.cancelCode#1f040578 phone_number:string phone_code_hash:string = Bool;
|
||||
auth.dropTempAuthKeys#8e48a188 except_auth_keys:Vector<long> = Bool;
|
||||
|
||||
account.registerDevice#5cbea590 token_type:int token:string app_sandbox:Bool secret:bytes other_uids:Vector<int> = Bool;
|
||||
|
@ -191,6 +191,7 @@ trait Tools
|
||||
try {
|
||||
Loop::run(function () use (&$resolved, &$value, &$exception, $promise) {
|
||||
$promise->onResolve(function ($e, $v) use (&$resolved, &$value, &$exception) {
|
||||
|
||||
Loop::stop();
|
||||
$resolved = true;
|
||||
$exception = $e;
|
||||
@ -329,7 +330,7 @@ trait Tools
|
||||
return;
|
||||
}
|
||||
$b = self::call($b());
|
||||
$b->onResolve(static function ($e, $res) use ($deferred) {
|
||||
$b->onResolve(function ($e, $res) use ($deferred) {
|
||||
if ($e) {
|
||||
if (isset($this)) {
|
||||
$this->rethrow($e, $file);
|
||||
|
@ -68,6 +68,9 @@ trait Loop
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
$needs_restart = true;
|
||||
}
|
||||
if (isset($_REQUEST['MadelineSelfRestart'])) {
|
||||
$this->logger->logger("Self-restarted, restart token ".$_REQUEST['MadelineSelfRestart']);
|
||||
}
|
||||
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
|
||||
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
@ -105,9 +108,31 @@ trait Loop
|
||||
if ($needs_restart) {
|
||||
$logger = &$this->logger;
|
||||
Shutdown::addCallback(static function () use (&$logger) {
|
||||
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
|
||||
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n");
|
||||
$logger->logger('Self-restarted');
|
||||
$address = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
|
||||
$params = $_GET;
|
||||
$params['MadelineSelfRestart'] = $this->random_int();
|
||||
|
||||
list($url, $query) = explode($uri, '?', 2);
|
||||
$query = http_build_query($params);
|
||||
$uri = implode('?', [$url, $query]);
|
||||
|
||||
$payload = $_SERVER['REQUEST_METHOD'].' '.$uri.' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n";
|
||||
|
||||
$logger->logger("Connecting to $address:$port");
|
||||
$a = fsockopen($address, $port);
|
||||
|
||||
$logger->logger("Sending self-restart payload");
|
||||
$logger->logger($payload);
|
||||
fwrite($a, $payload);
|
||||
|
||||
$logger->logger("Payload sent with token {$params['MadelineSelfRestart']}, waiting for self-restart");
|
||||
|
||||
sleep(10);
|
||||
fclose($a);
|
||||
}, 'restarter');
|
||||
}
|
||||
|
||||
@ -164,5 +189,8 @@ trait Loop
|
||||
ob_end_flush();
|
||||
flush();
|
||||
$GLOBALS['exited'] = true;
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
\fastcgi_finish_request();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ if (file_exists('.env')) {
|
||||
$dotenv->load();
|
||||
}
|
||||
if (getenv('TEST_SECRET_CHAT') == '') {
|
||||
echo('TEST_SECRET_CHAT is not defined in .env, please define it (copy .env.example).'.PHP_EOL);
|
||||
echo ('TEST_SECRET_CHAT is not defined in .env, please define it (copy .env.example).'.PHP_EOL);
|
||||
die(1);
|
||||
}
|
||||
echo 'Loading settings...'.PHP_EOL;
|
||||
|
Loading…
Reference in New Issue
Block a user