The session will no corrupt
This commit is contained in:
parent
e191bdc59d
commit
9c161dfc58
3
bot.php
3
bot.php
@ -17,6 +17,7 @@ $settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb
|
|||||||
try {
|
try {
|
||||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
|
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
if (file_exists('token.php')) {
|
if (file_exists('token.php')) {
|
||||||
require_once 'token.php';
|
require_once 'token.php';
|
||||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||||
@ -27,11 +28,9 @@ try {
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var_dump($a);
|
|
||||||
//var_dump($MadelineProto->API->get_config([], ['datacenter' => $MadelineProto->API->datacenter->curdc]));
|
//var_dump($MadelineProto->API->get_config([], ['datacenter' => $MadelineProto->API->datacenter->curdc]));
|
||||||
//var_dump($MadelineProto->API->settings['connection']);
|
//var_dump($MadelineProto->API->settings['connection']);
|
||||||
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('bot.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('bot.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
||||||
$MadelineProto->messages->sendMessage(['peer' => ['_' => 'inputPeerChat'], 'message' => '']);
|
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||||
|
@ -28,7 +28,17 @@ class Serialization
|
|||||||
*/
|
*/
|
||||||
public static function serialize($filename, $instance, $force = false)
|
public static function serialize($filename, $instance, $force = false)
|
||||||
{
|
{
|
||||||
return file_put_contents($filename, \danog\Serialization::serialize($instance, true), LOCK_EX);
|
if (!file_exists($lock = '.'.$filename.'.lock')) {
|
||||||
|
touch($lock);
|
||||||
|
clearstatcache();
|
||||||
|
}
|
||||||
|
$lock = fopen($lock, 'r');
|
||||||
|
flock($lock, LOCK_EX);
|
||||||
|
$wrote = file_put_contents('.'.$filename, \danog\Serialization::serialize($instance, true));
|
||||||
|
rename('.'.$filename, $filename);
|
||||||
|
flock($lock, LOCK_UN);
|
||||||
|
fclose($lock);
|
||||||
|
return $wrote;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,13 +53,16 @@ class Serialization
|
|||||||
public static function deserialize($filename, $no_updates = false)
|
public static function deserialize($filename, $no_updates = false)
|
||||||
{
|
{
|
||||||
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
||||||
|
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
$file = fopen($filename, 'r+');
|
if (!file_exists($lock = '.'.$filename.'.lock')) {
|
||||||
flock($file, LOCK_SH);
|
touch($lock);
|
||||||
$unserialized = stream_get_contents($file);
|
clearstatcache();
|
||||||
flock($file, LOCK_UN);
|
}
|
||||||
fclose($file);
|
$lock = fopen($lock, 'r');
|
||||||
|
flock($lock, LOCK_SH);
|
||||||
|
$unserialized = file_get_contents($filename);
|
||||||
|
flock($lock, LOCK_UN);
|
||||||
|
fclose($lock);
|
||||||
$unserialized = str_replace('O:26:"danog\MadelineProto\Button":', 'O:35:"danog\MadelineProto\TL\Types\Button":', $unserialized);
|
$unserialized = str_replace('O:26:"danog\MadelineProto\Button":', 'O:35:"danog\MadelineProto\TL\Types\Button":', $unserialized);
|
||||||
foreach (['RSA', 'TL\TLMethod', 'TL\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\Types\Button', 'TL\Types\Bytes', 'APIFactory'] as $class) {
|
foreach (['RSA', 'TL\TLMethod', 'TL\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\Types\Button', 'TL\Types\Bytes', 'APIFactory'] as $class) {
|
||||||
class_exists('\danog\MadelineProto\\'.$class);
|
class_exists('\danog\MadelineProto\\'.$class);
|
||||||
|
@ -14,7 +14,7 @@ namespace danog\MadelineProto\TL;
|
|||||||
|
|
||||||
trait PrettyException
|
trait PrettyException
|
||||||
{
|
{
|
||||||
private $tl_trace;
|
public $tl_trace;
|
||||||
|
|
||||||
public function getTLTrace()
|
public function getTLTrace()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user