-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.dp.is_mobile.php
89 lines (63 loc) · 2.09 KB
/
import.dp.is_mobile.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* User: Karel Wintersky <[email protected]>
* Date: 21.07.2019, time: 9:27
* Date: 02.12.2019, time: 5:00
*/
use Arris\DB;
use Arris\TimerStats;
ini_set('memory_limit', '1G');
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/class.DBPool.php';
require __DIR__ . '/class.ParseLogString.php';
use AJUR\LogEstimator\DBPool;
use AJUR\LogEstimator\ParseLogString;
TimerStats::init();
TimerStats::go();
DB::init(NULL, include '_connection_settings.php');
if ($argc < 2) {
\Arris\CLIConsole::say("<hr><br>Use {$argv[0]} <file.log> <br><br>");
die;
}
echo PHP_EOL;
$files_list = array_slice($argv, 1);
$files_count_total = count($files_list);
$pool_full = new DBPool(5000,
'log_doctorpiter_mobile',
[
// Summary/Legacy/isMobile/isTablet/UA
'dt',
'summary',
'nginx',
'ismobile',
'istablet',
'useragent',
]);
$logrecords_total = 0;
$files_count_current = 1;
// iterate args (all files)
foreach ($files_list as $file_name) {
if (!is_file($file_name)) {
\Arris\CLIConsole::say("File `{$file_name}` not found");
continue;
}
$strings_list = file($file_name); // read file
$logrecords_thisfile = 0;
// iterate all strings
foreach ($strings_list as $str) {
$data = ParseLogString::parse_isMobile($str);
if (!empty($data)) {
$pool_full->push($data);
$logrecords_thisfile++;
$logrecords_total++;
echo "[{$files_count_current}/{$files_count_total}] File: {$file_name} -- {$data['dt']} -- Rows: {$logrecords_thisfile} / Total: {$logrecords_total}" . "\r";
}
}
$pool_full->commit();
\Arris\CLIConsole::say("<br>{$file_name} completed with <font color='yellow'>{$logrecords_thisfile}</font> rows");
$files_count_current++;
}
$pool_full->commit();
\Arris\CLIConsole::say("<br>Task completed with <font color='yellow'>{$logrecords_total}</font> rows");
$time = round(TimerStats::stop(), 3);
\Arris\CLIConsole::say("Time consumed: <font color='yellow'>{$time}</font> sec.");