Bugfixes and docufixes

This commit is contained in:
Daniil Gentili 2017-12-23 15:33:19 +01:00
parent a1018576a0
commit 59473ebb31
5 changed files with 60 additions and 26 deletions

View File

@ -79,6 +79,15 @@ To install *all of the requirements* on `Ubuntu`, `Debian`, `Devuan`, or any oth
curl https://daniil.it/php.sh | sudo bash -e curl https://daniil.it/php.sh | sudo bash -e
``` ```
Or you can install PHP 7 from a PPA:
```
sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1 php7.1-dev php7.1-fpm php7.1-curl php7.1-xml php7.1-mbstring php7.1-zip -y
```
On other platforms, use [Google](https://google.com) to find out how to install the following dependencies. On other platforms, use [Google](https://google.com) to find out how to install the following dependencies.
@ -155,25 +164,26 @@ You can find examples for nearly every MadelineProto function in
### Storing sessions ### Storing sessions
VERY IMPORTANT: An istance of MadelineProto MUST be serialized every time an update is fetched, and on shutdown. To serialize MadelineProto to a file, do the following: To store information about an account session, serialization must be done.
When loading an already logged in session: An istance of MadelineProto is automatically serialized every `$settings['serialization']['serialization_interval']` seconds (by default 30 seconds), and on shutdown.
```
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->serialize();
```
When loading a new session: To set the serialization destination file, do the following:
When creating a new session:
``` ```
$MadelineProto = new \danog\MadelineProto\API($settings); $MadelineProto = new \danog\MadelineProto\API($settings);
$MadelineProto->session = 'session.madeline'; $MadelineProto->session = 'session.madeline'; // The session will be serialized to session.madeline
$MadelineProto->serialize(); $MadelineProto->serialize(); // Force first serialization
```
To load a serialized session:
```
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
``` ```
If the scripts shutsdown normally (without ctrl+c or fatal errors/exceptions), the session will be serialized automatically. If the scripts shutsdown normally (without ctrl+c or fatal errors/exceptions), the session will be serialized automatically.
It is **strongly** recommended to serialize the session with `$MadelineProto->serialize()` after every `$MadelineProto->get_updates()`.
## Methods ## Methods
@ -417,11 +427,15 @@ Here are the default values for the settings arrays and explanations for every s
'updates' => [ 'updates' => [
'handle_updates' => true, // Should I handle updates? 'handle_updates' => true, // Should I handle updates?
'handle_old_updates' => true, // Should I handle old updates on startup? 'handle_old_updates' => true, // Should I handle old updates on startup?
'getdifference_interval' => 30, // Manual difference polling interval
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter 'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
], ],
'secret_chats' => [ 'secret_chats' => [
'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats 'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats
], ],
'serialization' => [
'serialization_interval' => 30, // Automatic serialization interval
],
'threading' => [ 'threading' => [
'allow_threading' => false, // Should I use threading, if it is enabled? 'allow_threading' => false, // Should I use threading, if it is enabled?
'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have 'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have

View File

@ -83,6 +83,15 @@ To install *all of the requirements* on `Ubuntu`, `Debian`, `Devuan`, or any oth
curl https://daniil.it/php.sh | sudo bash -e curl https://daniil.it/php.sh | sudo bash -e
``` ```
Or you can install PHP 7 from a PPA:
```
sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1 php7.1-dev php7.1-fpm php7.1-curl php7.1-xml php7.1-mbstring php7.1-zip -y
```
On other platforms, use [Google](https://google.com) to find out how to install the following dependencies. On other platforms, use [Google](https://google.com) to find out how to install the following dependencies.
@ -159,25 +168,26 @@ You can find examples for nearly every MadelineProto function in
### Storing sessions ### Storing sessions
VERY IMPORTANT: An istance of MadelineProto MUST be serialized every time an update is fetched, and on shutdown. To serialize MadelineProto to a file, do the following: To store information about an account session, serialization must be done.
When loading an already logged in session: An istance of MadelineProto is automatically serialized every `$settings['serialization']['serialization_interval']` seconds (by default 30 seconds), and on shutdown.
```
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->serialize();
```
When loading a new session: To set the serialization destination file, do the following:
When creating a new session:
``` ```
$MadelineProto = new \danog\MadelineProto\API($settings); $MadelineProto = new \danog\MadelineProto\API($settings);
$MadelineProto->session = 'session.madeline'; $MadelineProto->session = 'session.madeline'; // The session will be serialized to session.madeline
$MadelineProto->serialize(); $MadelineProto->serialize(); // Force first serialization
```
To load a serialized session:
```
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
``` ```
If the scripts shutsdown normally (without ctrl+c or fatal errors/exceptions), the session will be serialized automatically. If the scripts shutsdown normally (without ctrl+c or fatal errors/exceptions), the session will be serialized automatically.
It is **strongly** recommended to serialize the session with `$MadelineProto->serialize()` after every `$MadelineProto->get_updates()`.
## Methods ## Methods
@ -421,11 +431,15 @@ Here are the default values for the settings arrays and explanations for every s
'updates' => [ 'updates' => [
'handle_updates' => true, // Should I handle updates? 'handle_updates' => true, // Should I handle updates?
'handle_old_updates' => true, // Should I handle old updates on startup? 'handle_old_updates' => true, // Should I handle old updates on startup?
'getdifference_interval' => 30, // Manual difference polling interval
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter 'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
], ],
'secret_chats' => [ 'secret_chats' => [
'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats 'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats
], ],
'serialization' => [
'serialization_interval' => 30, // Automatic serialization interval
],
'threading' => [ 'threading' => [
'allow_threading' => false, // Should I use threading, if it is enabled? 'allow_threading' => false, // Should I use threading, if it is enabled?
'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have 'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have

View File

@ -125,9 +125,9 @@ class APIFactory
$this->API->get_config([], ['datacenter' => $this->API->datacenter->curdc]); $this->API->get_config([], ['datacenter' => $this->API->datacenter->curdc]);
$aargs = isset($arguments[1]) && is_array($arguments[1]) ? $arguments[1] : []; $aargs = isset($arguments[1]) && is_array($arguments[1]) ? $arguments[1] : [];
$aargs['datacenter'] = $this->API->datacenter->curdc; $aargs['datacenter'] = $this->API->datacenter->curdc;
if ($name === 'get_updates' && isset($this->session) && !is_null($this->session) && time() - $this->serialized > 30) { if ($name === 'get_updates' && isset($this->session) && !is_null($this->session) && time() - $this->serialized > $this->API->settings['serialization']['serialization_interval']) {
$this->serialize($this->session);
Logger::log(["Didn't serialize in a while, doing that now..."]); Logger::log(["Didn't serialize in a while, doing that now..."]);
$this->serialize($this->session);
} }
if ($this->lua === false) { if ($this->lua === false) {
return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && is_array($arguments[0])) ? $arguments[0] : [], $aargs); return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && is_array($arguments[0])) ? $arguments[0] : [], $aargs);

View File

@ -46,7 +46,7 @@ class MTProto
/* /*
const V = 71; const V = 71;
*/ */
const V = 83; const V = 85;
const NOT_LOGGED_IN = 0; const NOT_LOGGED_IN = 0;
const WAITING_CODE = 1; const WAITING_CODE = 1;
@ -551,11 +551,15 @@ class MTProto
'updates' => [ 'updates' => [
'handle_updates' => true, // Should I handle updates? 'handle_updates' => true, // Should I handle updates?
'handle_old_updates' => true, // Should I handle old updates on startup? 'handle_old_updates' => true, // Should I handle old updates on startup?
'getdifference_interval' => 30, // Getdifference manual polling interval
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter 'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
], ],
'secret_chats' => [ 'secret_chats' => [
'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats 'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats
], ],
'serialization' => [
'serialization_interval' => 30, // Automatic serialization interval
],
'threading' => [ 'threading' => [
'allow_threading' => false, // Should I use threading, if it is enabled? 'allow_threading' => false, // Should I use threading, if it is enabled?
'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have 'handler_workers' => 10, // How many workers should every message handler pool of each socket reader have
@ -700,6 +704,8 @@ class MTProto
$socket->authorized = true; $socket->authorized = true;
break; break;
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'DC_ID_INVALID') break;
\danog\MadelineProto\Logger::log(['Failure while syncing authorization from DC '.$authorized_dc_id.' to DC '.$id.': '.$e->getMessage()], \danog\MadelineProto\Logger::ERROR);
} // Turns out this DC isn't authorized after all } // Turns out this DC isn't authorized after all
} }
} }

View File

@ -97,7 +97,7 @@ trait UpdateHandler
$only_updates = $this->handle_messages($this->datacenter->curdc); $only_updates = $this->handle_messages($this->datacenter->curdc);
} catch (\danog\MadelineProto\NothingInTheSocketException $e) { } catch (\danog\MadelineProto\NothingInTheSocketException $e) {
} }
if (time() - $this->last_recv > 30) { if (time() - $this->last_recv > $this->settings['updates']['getdifference_interval']) {
$this->get_updates_difference(); $this->get_updates_difference();
} }
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {