Add shutdown API
This commit is contained in:
parent
fd1234bfbd
commit
6a6fcb782d
@ -98,6 +98,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro
|
|||||||
* [Composer from scratch](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-scratch)
|
* [Composer from scratch](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-scratch)
|
||||||
* [Composer from existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project)
|
* [Composer from existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project)
|
||||||
* [Handling updates (new messages)](https://docs.madelineproto.xyz/docs/UPDATES.html)
|
* [Handling updates (new messages)](https://docs.madelineproto.xyz/docs/UPDATES.html)
|
||||||
|
* [Self-restart on webhosts](https://docs.madelineproto.xyz/docs/UPDATES.html#self-restart-on-webhosts)
|
||||||
* [Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
|
* [Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
|
||||||
* [Multi-account: Async Combined Event driven update handling](https://docs.madelineproto.xyz/docs/UPDATES.html#async-combined-event-driven)
|
* [Multi-account: Async Combined Event driven update handling](https://docs.madelineproto.xyz/docs/UPDATES.html#async-combined-event-driven)
|
||||||
* [Async Callback](https://docs.madelineproto.xyz/docs/UPDATES.html#async-callback)
|
* [Async Callback](https://docs.madelineproto.xyz/docs/UPDATES.html#async-callback)
|
||||||
|
2
docs
2
docs
@ -1 +1 @@
|
|||||||
Subproject commit dc05dc5cebfcec90ac7851928c522a4d635dbab6
|
Subproject commit 04cf2dff613a64382b3b135df2020bdcde756b1e
|
@ -38,6 +38,7 @@ class PasswordCalculator
|
|||||||
private $srp_B;
|
private $srp_B;
|
||||||
private $srp_BForHash;
|
private $srp_BForHash;
|
||||||
private $srp_id;
|
private $srp_id;
|
||||||
|
public $logger;
|
||||||
|
|
||||||
// This is needed do not remove this
|
// This is needed do not remove this
|
||||||
public function __construct($logger) { $this->logger = $logger; }
|
public function __construct($logger) { $this->logger = $logger; }
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
namespace danog\MadelineProto\Wrappers;
|
namespace danog\MadelineProto\Wrappers;
|
||||||
|
|
||||||
use Amp\Promise;
|
use Amp\Promise;
|
||||||
|
use danog\MadelineProto\Shutdown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages logging in and out.
|
* Manages logging in and out.
|
||||||
@ -63,7 +64,7 @@ trait Loop
|
|||||||
}
|
}
|
||||||
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
|
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
|
||||||
|
|
||||||
$backtrace = debug_backtrace(0);
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$lockfile = dirname(end($backtrace)['file']).'/bot.lock';
|
$lockfile = dirname(end($backtrace)['file']).'/bot.lock';
|
||||||
unset($backtrace);
|
unset($backtrace);
|
||||||
$try_locking = true;
|
$try_locking = true;
|
||||||
@ -91,15 +92,17 @@ trait Loop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register_shutdown_function(function () use ($lock, $needs_restart) {
|
Shutdown::addCallback(static function () use ($lock) {
|
||||||
flock($lock, LOCK_UN);
|
flock($lock, LOCK_UN);
|
||||||
fclose($lock);
|
fclose($lock);
|
||||||
if ($needs_restart) {
|
});
|
||||||
|
if ($needs_restart) {
|
||||||
|
Shutdown::addCallback(static function () {
|
||||||
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
|
$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");
|
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n");
|
||||||
$this->logger->logger('Self-restarted');
|
$this->logger->logger('Self-restarted');
|
||||||
}
|
}, 'restarter');
|
||||||
});
|
}
|
||||||
|
|
||||||
$this->closeConnection('Bot was started');
|
$this->closeConnection('Bot was started');
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ echo '{
|
|||||||
}' > composer.json
|
}' > composer.json
|
||||||
composer clearcache
|
composer clearcache
|
||||||
composer update
|
composer update
|
||||||
|
cp -a $madelinePath/src vendor/danog/madelineproto/
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
cp -a phar7 phar5
|
cp -a phar7 phar5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user