Add shutdown API docs

This commit is contained in:
Daniil Gentili 2019-06-06 15:57:08 +02:00
parent c0d6d9b93d
commit 04cf2dff61
2 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,7 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
Update handling can be done in different ways:
* [Self-restart on webhosts](#self-restart-on-webhosts)
* [Async Event driven](#async-event-driven)
* [Multi-account: Async Combined Event driven update handling](#async-combined-event-driven)
* [Async Callback](#async-callback)
@ -14,6 +15,35 @@ Update handling can be done in different ways:
* [Fetch all updates from the beginning](#fetch-all-updates-from-the-beginning)
## Self-restart on webhosts
When running the `loop()` method via web, MadelineProto will automatically enable a **magical self-restart hack**, to keep the bot running even on webhosts with limited execution time.
It relies on the shutdown function, so you must not set a custom shutdown function in your code, and instead use the **MadelineProto shutdown static API**:
```php
use danog\MadelineProto\Shutdown;
$id = Shutdown::addCallback(static function () {
// This function will run on shutdown
});
$id = Shutdown::addCallback(static function () {
// This function will run on shutdown
}, 'custom id');
$id = Shutdown::addCallback(static function () {
// This function will overwrite the previously set function with custom id
}, 'custom id');
$ok = Shutdown::removeCallback($id);
```
You can of course pass non-static functions, any type of callable is accepted.
A second optional parameter can also be accepted, containing the ID of the callable: you can use this if you want to later overwrite the callable with another callback, or remove it altogether.
The `removeCallback` will return true if the callback exists and it was removed correctly, false otherwise (as with all new MadelineProto 4.0 APIs, there are PHPDOCs for these methods so you'll see them in your IDE).
## Async Event driven
```php

View File

@ -103,6 +103,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)