-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot_fast.php
More file actions
executable file
·76 lines (59 loc) · 1.84 KB
/
bot_fast.php
File metadata and controls
executable file
·76 lines (59 loc) · 1.84 KB
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
71
72
73
74
75
76
<?PHP
ini_set('max_execution_time', 0); // 0 = Unlimited
ini_set('memory_limit','-1');
require_once ( __DIR__ . '/public_html/quickstatements.php' ) ;
if( isset($argv[1]) ){
$_GET['single_batch'] = 1;
$_GET['id'] = $argv[1];
$_GET['bypass'] = $argv[2];
}
function checkAndRunSingleBatch(){
if ( isset($_GET['single_batch']) && isset($_GET['id']) ) {
$qs = new QuickStatements ;
$db = $qs->getDB() ;
$sql = "SELECT * FROM batch WHERE id = " . $_GET['id'];
$query = $db->query($sql);
$result = $query->fetch_object();
if (!$result) {
echo('Error: Specified id from URL parameter does not exist in the database.<br>');
die;
}
if ( $result->status == 'INIT' || $result->status == 'STOP') {
// queue the batch
if ( !$qs->queueBatch($result->id) ) {
echo 'died';
print "{$result->id}: " . $qs->last_error_message."\n" ;
return 0;
}
} else if ($result->status == 'DONE') {
echo('Error: The specified batch id "'. $_GET['id'] .'" has already been processed (has a status of DONE).');
die;
}
$isBatchRunning = $qs->checkForRunFastStatus($result->id);
if( $isBatchRunning && !isset($_GET['bypass']) ){
die; // queue the batch instead of injest
}
$qs->setStatusToRunFast($result->id);
$max_num_bots = 40;
if( $max_num_bots > $result->total_rows ){
$max_num_bots = $result->total_rows;
}
for($i=1;$i<=$max_num_bots;$i++){
echo exec("/opt/local/bin/php botChild.php $i {$result->id} $max_num_bots {$result->total_rows} >/dev/null 2>&1 &", $out, $v);
}
$i = $i -1;
echo "bots spawned: $i<br>";
return 1;
} else {
echo '<br>';
if (!isset($_GET['single_batch']))
echo 'Error: "single_batch" URL parameter is not set.<br>';
if (!isset($_GET['id']))
echo 'Error: "id" URL parameter is not set.<br>';
die;
}
}
if ( checkAndRunSingleBatch() ) {
echo('Started a batch.');
}
?>