diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 3f78864e..25535703 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -30,6 +30,7 @@ class API extends APIFactory clearstatcache(); } $lock = fopen($lock, 'r'); + \danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']); flock($lock, LOCK_SH); $unserialized = file_get_contents($params); flock($lock, LOCK_UN); diff --git a/src/danog/MadelineProto/Logger.php b/src/danog/MadelineProto/Logger.php index 54dda793..bc689726 100644 --- a/src/danog/MadelineProto/Logger.php +++ b/src/danog/MadelineProto/Logger.php @@ -81,7 +81,7 @@ class Logger ]; public static $storage = []; - public static $mode = null; + public static $mode = 1; public static $optional = null; public static $constructed = false; public static $prefix = ''; @@ -165,7 +165,7 @@ class Logger return false; } if (!self::$constructed) { - throw new Exception(\danog\MadelineProto\Lang::$current_lang['constructor_function_uncalled']); +// throw new Exception(\danog\MadelineProto\Lang::$current_lang['constructor_function_uncalled']); } $prefix = self::$prefix; if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) { diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 78af648c..cb3f37b6 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -240,11 +240,15 @@ trait Files $file = realpath($file); $message_media = $this->get_download_info($message_media); $stream = fopen($file, 'r+b'); + \danog\MadelineProto\Logger::log(['Waiting for lock of file to download...']); flock($stream, LOCK_EX); - $this->download_to_stream($message_media, $stream, $cb, filesize($file), -1); - flock($stream, LOCK_UN); - fclose($stream); - clearstatcache(); + try { + $this->download_to_stream($message_media, $stream, $cb, filesize($file), -1); + } finally { + flock($stream, LOCK_UN); + fclose($stream); + clearstatcache(); + } return $file; } @@ -265,7 +269,7 @@ trait Files $end = $message_media['size']; } $size = $end - $offset; - $part_size = 128 * 1024; + $part_size = 1024 * 1024; $percent = 0; $datacenter = isset($message_media['InputFileLocation']['dc_id']) ? $message_media['InputFileLocation']['dc_id'] : $this->datacenter->curdc; if (isset($message_media['key'])) { @@ -290,9 +294,6 @@ trait Files $res = $cdn ? $this->method_call('upload.getCdnFile', ['file_token' => $message_media['file_token'], 'offset' => $offset, 'limit' => $part_size], ['heavy' => true, 'datacenter' => $datacenter]) : $this->method_call('upload.getFile', ['location' => $message_media['InputFileLocation'], 'offset' => $offset, 'limit' => $part_size], ['heavy' => true, 'datacenter' => &$datacenter]); } catch (\danog\MadelineProto\RPCErrorException $e) { switch ($e->rpc) { - case 'OFFSET_INVALID': - //\Rollbar\Rollbar::log(\Rollbar\Payload\Level::error(), $e->rpc, ['info' => $message_media, 'offset' => $offset]); - break; case 'FILE_TOKEN_INVALID': $cdn = false; continue 2; diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index c6e2a60b..463107c3 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -52,11 +52,15 @@ class Serialization clearstatcache(); } $lock = fopen($lock, 'w'); + \danog\MadelineProto\Logger::log(['Waiting for exclusive lock of serialization lockfile...']); flock($lock, LOCK_EX); - $wrote = file_put_contents($filename.'.temp.session', serialize($instance)); - rename($filename.'.temp.session', $filename); - flock($lock, LOCK_UN); - fclose($lock); + try { + $wrote = file_put_contents($filename.'.temp.session', serialize($instance)); + rename($filename.'.temp.session', $filename); + } finally { + flock($lock, LOCK_UN); + fclose($lock); + } return $wrote; } @@ -78,6 +82,8 @@ class Serialization clearstatcache(); } $lock = fopen($lock, 'r'); + + \danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']); flock($lock, LOCK_SH); $unserialized = file_get_contents($filename); flock($lock, LOCK_UN);