-
Notifications
You must be signed in to change notification settings - Fork 2
/
BotsController.php
71 lines (53 loc) · 1.65 KB
/
BotsController.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
66
67
68
69
70
<?php
require 'vendor/autoload.php';
use Repository\AccountsRepository;
const MAX_PROCESSES_COUNT = 2;
const ACTUAL_ACCOUNTS_GET_DELAY = 120;
function createNewProcess(){
global $processes;
global $accounts;
global $proxies;
if(count($accounts) > 0) {
$account = array_shift($accounts);
$proxyArray = [];
foreach ($proxies as &$proxy)
if(!$proxy['isUsed']){
$proxyArray = $proxy;
$proxy['isUsed'] = true;
break;
}
array_push($processes, proc_open(
'php BotProcess.php ' . $account->getId() . ' ' . $proxyArray['ip'] . ' ' . $proxyArray['port'] ,
[], $pipes, null, null
)
);
$account->setInProcess(true);
AccountsRepository::update($account);
}
}
function filterProcesses(){
global $processes;
foreach ($processes as &$process)
if(!proc_get_status($process)['running'])
$process = null;
$processes = array_filter($processes);
}
$processes = [];
$accounts = [];
$proxies = [
['ip' => '206.81.2.4', 'port' => '808', 'isUsed' => false],
['ip' => '183.88.212.141', 'port' => '8080', 'isUsed' => false]
];
while(true) {
AccountsRepository::deleteInvalidAccounts();
$accounts = AccountsRepository::getActualAccounts();
filterProcesses();
if(count($accounts) != 0)
\Util\Logger::logToConsole("Accounts in work: " . count($accounts));
while (count($processes) < MAX_PROCESSES_COUNT)
if (count($accounts) != 0)
createNewProcess();
else
break;
sleep(ACTUAL_ACCOUNTS_GET_DELAY);
}