From cac6b68920201618035e749ac030d5e4ac765707 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 16 Jan 2017 01:54:51 +0100 Subject: [PATCH] Lock while serializing --- src/danog/MadelineProto/Serialization.php | 2 +- src/danog/MadelineProto/Wrappers/FilesHandler.php | 4 +++- src/danog/MadelineProto/Wrappers/Login.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index 48634993..cf86f613 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -22,7 +22,7 @@ class Serialization if ($instance->API->should_serialize || !(file_exists($filename) && !empty(file_get_contents($filename))) || $force) { $instance->API->should_serialize = false; - return file_put_contents($filename, serialize($instance)); + return file_put_contents($filename, serialize($instance), LOCK_EX); } return false; diff --git a/src/danog/MadelineProto/Wrappers/FilesHandler.php b/src/danog/MadelineProto/Wrappers/FilesHandler.php index 30276c92..77fc1746 100644 --- a/src/danog/MadelineProto/Wrappers/FilesHandler.php +++ b/src/danog/MadelineProto/Wrappers/FilesHandler.php @@ -554,7 +554,9 @@ trait FilesHandler while ($percent < 100) { $real_part_size = ($offset + $part_size > $end) ? $part_size - (($offset + $part_size) - $end) : $part_size; \danog\MadelineProto\Logger::log($real_part_size, $offset); - \danog\MadelineProto\Logger::log(fwrite($stream, $this->API->method_call('upload.getFile', ['location' => $info['InputFileLocation'], 'offset' => $offset, 'limit' => $real_part_size], null, true)['bytes'])); + $res = $this->API->method_call('upload.getFile', ['location' => $info['InputFileLocation'], 'offset' => $offset, 'limit' => $real_part_size], null, true); + //\danog\MadelineProto\Logger::log($res); + \danog\MadelineProto\Logger::log(fwrite($stream, $res['bytes'])); \danog\MadelineProto\Logger::log($offset, $size, ftell($stream)); $cb($percent = ($offset += $real_part_size) * 100 / $size); } diff --git a/src/danog/MadelineProto/Wrappers/Login.php b/src/danog/MadelineProto/Wrappers/Login.php index a4513d96..53652eff 100644 --- a/src/danog/MadelineProto/Wrappers/Login.php +++ b/src/danog/MadelineProto/Wrappers/Login.php @@ -52,7 +52,7 @@ trait Login $this->API->updates_key = 0; $this->API->get_updates_state(); $this->API->should_serialize = true; - + if (!isset($this->API->settings['pwr']['pwr']) || !$this->settings['pwr']['pwr']) file_get_contents('https://api.pwrtelegram.xyz/bot'.$token.'/getme'); \danog\MadelineProto\Logger::log('Logged in successfully!'); return $this->API->datacenter->authorization;