Better logging
This commit is contained in:
parent
dd43474e75
commit
b4e6d022ed
@ -52,7 +52,9 @@ class Exception extends \Exception
|
|||||||
$this->line = $line;
|
$this->line = $line;
|
||||||
}
|
}
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
|
if (strpos($message, 'socket_accept') === false) {
|
||||||
\danog\MadelineProto\Logger::log($message.' in '.basename($this->file).':'.$this->line, \danog\MadelineProto\Logger::FATAL_ERROR);
|
\danog\MadelineProto\Logger::log($message.' in '.basename($this->file).':'.$this->line, \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||||
|
}
|
||||||
if (in_array($message, ['The session is corrupted!', 'Re-executing query...', 'I had to recreate the temporary authorization key', 'This peer is not present in the internal peer database', "Couldn't get response", 'Chat forbidden', 'The php-libtgvoip extension is required to accept and manage calls. See daniil.it/MadelineProto for more info.', 'File does not exist', 'Please install this fork of phpseclib: https://github.com/danog/phpseclib'])) {
|
if (in_array($message, ['The session is corrupted!', 'Re-executing query...', 'I had to recreate the temporary authorization key', 'This peer is not present in the internal peer database', "Couldn't get response", 'Chat forbidden', 'The php-libtgvoip extension is required to accept and manage calls. See daniil.it/MadelineProto for more info.', 'File does not exist', 'Please install this fork of phpseclib: https://github.com/danog/phpseclib'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ class Server
|
|||||||
if (!extension_loaded('pcntl')) {
|
if (!extension_loaded('pcntl')) {
|
||||||
throw new Exception(['extension', 'pcntl']);
|
throw new Exception(['extension', 'pcntl']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->mypid = getmypid();
|
$this->mypid = getmypid();
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,11 @@ namespace danog\MadelineProto\Server;
|
|||||||
*/
|
*/
|
||||||
class Proxy extends \danog\MadelineProto\Connection
|
class Proxy extends \danog\MadelineProto\Connection
|
||||||
{
|
{
|
||||||
use \danog\MadelineProto\Tools;
|
|
||||||
private $madeline;
|
|
||||||
|
|
||||||
public function __magic_construct($socket, $extra, $ip, $port, $protocol, $timeout, $ipv6)
|
public function __magic_construct($socket, $extra, $ip, $port, $protocol, $timeout, $ipv6)
|
||||||
{
|
{
|
||||||
\danog\MadelineProto\Logger::log('Got connection '.getmypid().'!');
|
\danog\MadelineProto\Logger::log('Got connection '.getmypid().'!');
|
||||||
\danog\MadelineProto\Magic::$pid = getmypid();
|
\danog\MadelineProto\Magic::$pid = getmypid();
|
||||||
|
\danog\MadelineProto\Lang::$current_lang = [];
|
||||||
$this->sock = $socket;
|
$this->sock = $socket;
|
||||||
$this->sock->setBlocking(true);
|
$this->sock->setBlocking(true);
|
||||||
$this->must_open = false;
|
$this->must_open = false;
|
||||||
@ -32,11 +30,14 @@ class Proxy extends \danog\MadelineProto\Connection
|
|||||||
$this->sock->setOption(\SOL_SOCKET, \SO_SNDTIMEO, $extra['timeout']);
|
$this->sock->setOption(\SOL_SOCKET, \SO_SNDTIMEO, $extra['timeout']);
|
||||||
$this->logger = new \danog\MadelineProto\Logger(3);
|
$this->logger = new \danog\MadelineProto\Logger(3);
|
||||||
$this->extra = $extra;
|
$this->extra = $extra;
|
||||||
|
if ($this->extra['madeline'] instanceof \danog\MadelineProto\API) {
|
||||||
|
$this->extra['madeline'] = $this->extra['madeline']->API->datacenter->sockets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
echo 'Closing socket in fork '.getmypid().PHP_EOL;
|
\danog\MadelineProto\Logger::log('Closing fork '.getmypid().'!');
|
||||||
unset($this->sock);
|
unset($this->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,20 +68,19 @@ class Proxy extends \danog\MadelineProto\Connection
|
|||||||
}
|
}
|
||||||
$dc = abs(unpack('s', substr($random, 60, 2))[1]);
|
$dc = abs(unpack('s', substr($random, 60, 2))[1]);
|
||||||
|
|
||||||
$socket = $this->extra['madeline']->API->datacenter->sockets[$dc];
|
$socket = $this->extra['madeline'][$dc];
|
||||||
$socket->__construct($socket->proxy, $socket->extra, $socket->ip, $socket->port, $socket->protocol, $this->extra['timeout'], $socket->ipv6);
|
$socket->__construct($socket->proxy, $socket->extra, $socket->ip, $socket->port, $socket->protocol, $timeout = $this->extra['timeout'], $socket->ipv6);
|
||||||
|
|
||||||
unset($this->extra);
|
unset($this->extra);
|
||||||
|
|
||||||
$write = [];
|
$write = [];
|
||||||
$except = [];
|
$except = [];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
pcntl_signal_dispatch();
|
pcntl_signal_dispatch();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$read = [$this->getSocket(), $socket->getSocket()];
|
$read = [$this->getSocket(), $socket->getSocket()];
|
||||||
\Socket::select($read, $write, $except, 2);
|
\Socket::select($read, $write, $except, $timeout);
|
||||||
if (isset($read[0])) {
|
if (isset($read[0])) {
|
||||||
//\danog\MadelineProto\Logger::log("Will write to DC $dc on ".\danog\MadelineProto\Magic::$pid);
|
//\danog\MadelineProto\Logger::log("Will write to DC $dc on ".\danog\MadelineProto\Magic::$pid);
|
||||||
$socket->send_message($this->read_message());
|
$socket->send_message($this->read_message());
|
||||||
@ -89,8 +89,8 @@ class Proxy extends \danog\MadelineProto\Connection
|
|||||||
//\danog\MadelineProto\Logger::log("Will read from DC $dc on ".\danog\MadelineProto\Magic::$pid);
|
//\danog\MadelineProto\Logger::log("Will read from DC $dc on ".\danog\MadelineProto\Magic::$pid);
|
||||||
$this->send_message($socket->read_message());
|
$this->send_message($socket->read_message());
|
||||||
}
|
}
|
||||||
|
if (empty($read)) throw new \danog\MadelineProto\NothingInTheSocketException('Inactivity');
|
||||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||||
echo $e;
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user