Multiple fixes
This commit is contained in:
parent
588e77a331
commit
120ff0aba9
|
@ -133,7 +133,7 @@ class APIFactory extends AsyncConstruct
|
||||||
|
|
||||||
public function __call($name, $arguments)
|
public function __call($name, $arguments)
|
||||||
{
|
{
|
||||||
$yielded = $this->__call_async($name, $arguments);
|
$yielded = $this->call($this->__call_async($name, $arguments));
|
||||||
$async = $this->lua === false && (is_array(end($arguments)) && isset(end($arguments)['async']) ? end($arguments)['async'] : ($this->async && $name !== 'loop'));
|
$async = $this->lua === false && (is_array(end($arguments)) && isset(end($arguments)['async']) ? end($arguments)['async'] : ($this->async && $name !== 'loop'));
|
||||||
if ($async) {
|
if ($async) {
|
||||||
return $yielded;
|
return $yielded;
|
||||||
|
@ -158,15 +158,7 @@ class APIFactory extends AsyncConstruct
|
||||||
yield $this->initAsync();
|
yield $this->initAsync();
|
||||||
}
|
}
|
||||||
if (Magic::is_fork() && !Magic::$processed_fork) {
|
if (Magic::is_fork() && !Magic::$processed_fork) {
|
||||||
throw new Exception("Forking not supported");
|
throw new Exception("Forking not supported, use async logic, instead: https://docs.madelineproto.xyz/docs/ASYNC.html");
|
||||||
/*
|
|
||||||
\danog\MadelineProto\Logger::log('Detected fork');
|
|
||||||
$this->API->reset_session();
|
|
||||||
foreach ($this->API->datacenter->sockets as $datacenter) {
|
|
||||||
yield $datacenter->reconnect();
|
|
||||||
}
|
|
||||||
Magic::$processed_fork = true;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
if (isset($this->session) && !is_null($this->session) && time() - $this->serialized > $this->API->settings['serialization']['serialization_interval']) {
|
if (isset($this->session) && !is_null($this->session) && time() - $this->serialized > $this->API->settings['serialization']['serialization_interval']) {
|
||||||
Logger::log("Didn't serialize in a while, doing that now...");
|
Logger::log("Didn't serialize in a while, doing that now...");
|
||||||
|
|
|
@ -122,6 +122,7 @@ class CombinedAPI
|
||||||
if (\danog\MadelineProto\Magic::$has_thread && is_object(\Thread::getCurrentThread()) || Magic::is_fork()) {
|
if (\danog\MadelineProto\Magic::$has_thread && is_object(\Thread::getCurrentThread()) || Magic::is_fork()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->serialize();
|
$this->serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,34 @@ final class Coroutine implements Promise
|
||||||
*/
|
*/
|
||||||
public function __construct(\Generator $generator)
|
public function __construct(\Generator $generator)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
$this->generator = new class($generator) {
|
||||||
|
private $s = '';
|
||||||
|
private $g;
|
||||||
|
private $trace;
|
||||||
|
public function __construct($g) {
|
||||||
|
$this->g = $g;
|
||||||
|
$this->s .= spl_object_hash($this).', ';
|
||||||
|
}
|
||||||
|
public function __call($a, $args) {
|
||||||
|
$this->s .= "$a, ";
|
||||||
|
try {
|
||||||
|
$res = $this->g->{$a}(...$args);
|
||||||
|
if (is_array($res) && isset($res['my_trace'])) {
|
||||||
|
$this->trace = $res;
|
||||||
|
$res = $this->g->{$a}(...$args);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->s .= $e->getMessage();
|
||||||
|
$this->s .= ', ';
|
||||||
|
var_dump($this->s, $this->trace);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//public function __destruct() { var_dump($this->s); }
|
||||||
|
};*/
|
||||||
$this->generator = $generator;
|
$this->generator = $generator;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$yielded = $this->generator->current();
|
$yielded = $this->generator->current();
|
||||||
while (!$yielded instanceof Promise) {
|
while (!$yielded instanceof Promise) {
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
namespace danog\MadelineProto;
|
namespace danog\MadelineProto;
|
||||||
|
|
||||||
use Amp\ByteStream\ResourceOutputStream;
|
use Amp\ByteStream\ResourceOutputStream;
|
||||||
|
use Amp\Failure;
|
||||||
|
use function \Amp\ByteStream\getStdout;
|
||||||
|
use function \Amp\ByteStream\getStderr;
|
||||||
|
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
|
@ -96,18 +99,18 @@ class Logger
|
||||||
$this->newline = PHP_EOL;
|
$this->newline = PHP_EOL;
|
||||||
|
|
||||||
if ($this->mode === 3) {
|
if ($this->mode === 3) {
|
||||||
$this->stdout = new ResourceOutputStream(STDOUT);
|
$this->stdout = getStdout();
|
||||||
if (php_sapi_name() !== 'cli') $this->newline = '<br>'.$this->newline;
|
if (php_sapi_name() !== 'cli') $this->newline = '<br>'.$this->newline;
|
||||||
} elseif ($this->mode === 2) {
|
} elseif ($this->mode === 2) {
|
||||||
$this->stdout = new ResourceOutputStream(fopen($this->optional, 'a+'));
|
$this->stdout = new ResourceOutputStream(fopen($this->optional, 'a+'));
|
||||||
} elseif ($this->mode === 1) {
|
} elseif ($this->mode === 1) {
|
||||||
$result = @ini_get('error_log');
|
$result = @ini_get('error_log');
|
||||||
if ($result === 'syslog') {
|
if ($result === 'syslog') {
|
||||||
$this->stdout = new ResourceOutputStream(STDERR);
|
$this->stdout = getStderr();
|
||||||
} elseif ($result) {
|
} elseif ($result) {
|
||||||
$this->stdout = new ResourceOutputStream(fopen($result, 'a+'));
|
$this->stdout = new ResourceOutputStream(fopen($result, 'a+'));
|
||||||
} else {
|
} else {
|
||||||
$this->stdout = new ResourceOutputStream(STDERR);
|
$this->stdout = getStderr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,9 +145,6 @@ class Logger
|
||||||
if (\danog\MadelineProto\Magic::$has_thread && is_object(\Thread::getCurrentThread())) {
|
if (\danog\MadelineProto\Magic::$has_thread && is_object(\Thread::getCurrentThread())) {
|
||||||
$prefix .= ' (t)';
|
$prefix .= ' (t)';
|
||||||
}
|
}
|
||||||
if (\danog\MadelineProto\Magic::is_fork()) {
|
|
||||||
$prefix .= ' (p)';
|
|
||||||
}
|
|
||||||
if (!is_string($param)) {
|
if (!is_string($param)) {
|
||||||
$param = json_encode($param, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
$param = json_encode($param, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
}
|
}
|
||||||
|
@ -157,12 +157,15 @@ class Logger
|
||||||
$this->stdout->write($param.$this->newline);
|
$this->stdout->write($param.$this->newline);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->stdout->write(Magic::$isatty ? "\33[".$this->colors[$level].'m'.$param."\33[0m".$this->newline : $param.$this->newline);
|
$param = Magic::$isatty ? "\33[".$this->colors[$level].'m'.$param."\33[0m".$this->newline : $param.$this->newline;
|
||||||
|
if ($this->stdout->write($param) instanceof Failure) {
|
||||||
|
echo "(closed) $param";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
$this->wait($this->stdout->write(''));
|
//$this->wait($this->stdout->write(''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ abstract class Loop implements LoopInterface
|
||||||
|
|
||||||
private function loopImpl()
|
private function loopImpl()
|
||||||
{
|
{
|
||||||
|
//yield ['my_trace' => debug_backtrace(0, 1)[0], (string) $this];
|
||||||
$this->startedLoop();
|
$this->startedLoop();
|
||||||
$this->API->logger->logger("Entered $this", Logger::ULTRA_VERBOSE);
|
$this->API->logger->logger("Entered $this", Logger::ULTRA_VERBOSE);
|
||||||
try {
|
try {
|
||||||
|
@ -62,6 +63,7 @@ abstract class Loop implements LoopInterface
|
||||||
} finally {
|
} finally {
|
||||||
$this->exitedLoop();
|
$this->exitedLoop();
|
||||||
$this->API->logger->logger("Exited $this", Logger::ULTRA_VERBOSE);
|
$this->API->logger->logger("Exited $this", Logger::ULTRA_VERBOSE);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,8 @@ trait ResponseHandler
|
||||||
break;
|
break;
|
||||||
case 'msg_detailed_info':
|
case 'msg_detailed_info':
|
||||||
$this->datacenter->sockets[$datacenter]->check_in_seq_no($current_msg_id);
|
$this->datacenter->sockets[$datacenter]->check_in_seq_no($current_msg_id);
|
||||||
|
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
|
||||||
|
|
||||||
$only_updates = false;
|
$only_updates = false;
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']])) {
|
if (isset($this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']])) {
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['answer_msg_id']])) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['answer_msg_id']])) {
|
||||||
|
|
|
@ -61,7 +61,6 @@ trait Events
|
||||||
$this->settings['updates']['callback'] = [$this, 'event_update_handler'];
|
$this->settings['updates']['callback'] = [$this, 'event_update_handler'];
|
||||||
$this->settings['updates']['handle_updates'] = true;
|
$this->settings['updates']['handle_updates'] = true;
|
||||||
$this->settings['updates']['run_callback'] = true;
|
$this->settings['updates']['run_callback'] = true;
|
||||||
|
|
||||||
if (!$this->asyncInitPromise) {
|
if (!$this->asyncInitPromise) {
|
||||||
$this->startUpdateSystem();
|
$this->startUpdateSystem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,12 @@ trait Loop
|
||||||
public function loop_async($max_forks = 0)
|
public function loop_async($max_forks = 0)
|
||||||
{
|
{
|
||||||
if (is_callable($max_forks)) {
|
if (is_callable($max_forks)) {
|
||||||
|
$this->logger->logger('Running async callable and exiting from loop');
|
||||||
return yield $max_forks();
|
return yield $max_forks();
|
||||||
}
|
}
|
||||||
if (in_array($this->settings['updates']['callback'], [['danog\\MadelineProto\\API', 'get_updates_update_handler'], 'get_updates_update_handler'])) {
|
if (in_array($this->settings['updates']['callback'], [['danog\\MadelineProto\\API', 'get_updates_update_handler'], 'get_updates_update_handler'])) {
|
||||||
return true;
|
$this->logger->logger('Getupdates event handler is enabled, exiting from loop', \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!is_callable($this->loop_callback) || (is_array($this->loop_callback) && $this->loop_callback[1] === 'onLoop' && !method_exists(...$this->loop_callback))) {
|
if (!is_callable($this->loop_callback) || (is_array($this->loop_callback) && $this->loop_callback[1] === 'onLoop' && !method_exists(...$this->loop_callback))) {
|
||||||
$this->loop_callback = null;
|
$this->loop_callback = null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user