This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
syncsessions.php
65 lines (60 loc) · 2.69 KB
/
syncsessions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require 'vendor/autoload.php';
require '../storage_url.php';
ini_set('log_errors', 1);
//ini_set('error_log', '/tmp/maintainance.log');
$pids = [];
$sessions = glob('../sessions/*.madeline');
foreach ($sessions as $key => $session) {
echo 'Creating fork ('.($key * 100 / count($sessions)).'%, '.count($pids)." processes running)\n";
if (($pid = pcntl_fork()) === 0) {
try {
$madeline = new \danog\MadelineProto\API($session, ['logger' => ['logger_level' => 5], 'connection_settings' => ['all' => ['protocol' => 'tcp_abridged']], 'peer' => ['cache_all_peers_on_startup' => true, 'full_fetch' => true], 'pwr' => ['db_token' => $db_token, 'pwr' => true, 'strict' => true]]);
$madeline = new \danog\MadelineProto\API($session, ['logger' => ['logger_level' => 4], 'connection_settings' => ['all' => ['protocol' => 'tcp_abridged']], 'peer' => ['cache_all_peers_on_startup' => true, 'full_fetch' => true], 'pwr' => ['db_token' => $db_token, 'pwr' => true, 'strict' => true]]);
$dialogs = false;
try {
$dialogs = $madeline->get_dialogs(false);
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
/*if (!$dialogs) {
foreach ($madeline->API->chats as $chat) {
try {
$madeline->get_pwr_chat($chat);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if (in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHAT_FORBIDDEN'])) continue;
if (preg_match('/FLOOD_WAIT_(\d*)/', $e->rpc, $matches)) {
sleep($matches[1]);
continue;
}
throw $e;
}
}
}*/
$madeline->store_db([], true);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED', 'USER_DEACTIVATED'])) {
echo "Deleting session $session after ".$e->rpc.'...'.PHP_EOL;
if (isset($madeline)) {
unset($madeline->session);
}
foreach (glob($session.'*') as $path) {
rename($path, '../brokensessions/'.basename($path));
}
exit;
}
echo $e;
} catch (Exception $e) {
echo $e;
}
exit;
}
$pids[] = $pid;
while (count($pids) > 20) {
foreach ($pids as $key => $pid) {
if (pcntl_waitpid($pid, $status, WNOHANG)) {
unset($pids[$key]);
}
}
sleep(1);
}
}