diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 1ecab57f..e3f80261 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -5577,7 +5577,16 @@ class InternalDoc extends APIFactory return $this->__call(__FUNCTION__, [$callback, $extra]); } /** - * Close connection with server. + * Stop update loop. + * + * @return void + */ + public function stop(): void + { + $this->API->stop(); + } + /** + * Close connection with client, connected via web. * * @param string $message Message * diff --git a/src/danog/MadelineProto/Wrappers/Loop.php b/src/danog/MadelineProto/Wrappers/Loop.php index d793faa0..db2e6414 100644 --- a/src/danog/MadelineProto/Wrappers/Loop.php +++ b/src/danog/MadelineProto/Wrappers/Loop.php @@ -29,6 +29,12 @@ use danog\MadelineProto\Tools; trait Loop { private $loop_callback; + /** + * Whether to stop the loop. + * + * @var boolean + */ + private $stopLoop = false; /** * Set loop callback (DEPRECATED). @@ -164,7 +170,8 @@ trait Loop $this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE); - while (true) { + $this->stopLoop = false; + do { $updates = $this->updates; $this->updates = []; foreach ($updates as $update) { @@ -177,14 +184,25 @@ trait Loop if ($this->loop_callback !== null) { $callback = $this->loop_callback; - $callback(); + Tools::callForkDefer($callback()); } yield $this->waitUpdate(); - } + } while (!$this->stopLoop); + $this->stopLoop = false; + } + /** + * Stop update loop. + * + * @return void + */ + public function stop(): void + { + $this->stopLoop = true; + $this->signalUpdate(); } /** - * Close connection with server. + * Close connection with client, connected via web. * * @param string $message Message * diff --git a/tools/makephar.php b/tools/makephar.php index 126f6db7..fc38e6ce 100755 --- a/tools/makephar.php +++ b/tools/makephar.php @@ -32,11 +32,11 @@ if (!isset($backtrace[0]["file"]) || !in_array(basename($backtrace[0]["file"]), if (isset($backtrace[1]["file"])) { @chdir(dirname($backtrace[1]["file"])); } -if ($contents = file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new")) { +if ($contents = file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new".rand(0, PHP_INT_MAX))) { file_put_contents($backtrace[0]["file"], $contents); } -Phar::interceptFileFuncs(); +Phar::interceptFileFuncs(); Phar::mapPhar("'.$argv[2].'"); return require_once "phar://'.$argv[2].'/vendor/autoload.php";