Add shutdown API

This commit is contained in:
Daniil Gentili 2019-06-06 15:57:21 +02:00
parent fd1234bfbd
commit 6a6fcb782d
5 changed files with 12 additions and 6 deletions

View File

@ -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 existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project)
* [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)
* [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)

2
docs

@ -1 +1 @@
Subproject commit dc05dc5cebfcec90ac7851928c522a4d635dbab6
Subproject commit 04cf2dff613a64382b3b135df2020bdcde756b1e

View File

@ -38,6 +38,7 @@ class PasswordCalculator
private $srp_B;
private $srp_BForHash;
private $srp_id;
public $logger;
// This is needed do not remove this
public function __construct($logger) { $this->logger = $logger; }

View File

@ -20,6 +20,7 @@
namespace danog\MadelineProto\Wrappers;
use Amp\Promise;
use danog\MadelineProto\Shutdown;
/**
* Manages logging in and out.
@ -63,7 +64,7 @@ trait Loop
}
$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';
unset($backtrace);
$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);
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']);
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');
}
});
}, 'restarter');
}
$this->closeConnection('Bot was started');
}

View File

@ -40,6 +40,7 @@ echo '{
}' > composer.json
composer clearcache
composer update
cp -a $madelinePath/src vendor/danog/madelineproto/
cd ..
cp -a phar7 phar5