-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.php
57 lines (49 loc) · 1.42 KB
/
parser.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
<?php
$rustart = getrusage();
include_once "LogParser.php";
include_once "Controller/ApacheLogController.php";
include_once "Conf/config.php";
try {
passthru('clear');
echo $header;
echo "Script start...\n";
if ($options = getopt("f::d::t::h::")) {
if (isset($options['h'])) {
echo $help;
die();
}
if (isset($options['f']))
$log_file = $options['f'];
if (isset($options['d']))
$db = $options['d'];
if (isset($options['t']))
$table = $options['t'];
}
$i = 0;
$parser = new LogParser();
$data = new ApacheLogController($username, $password, $servername, $db, $table);
echo "Parsing file: " . $log_file . "\n";
$handle = fopen($log_file, "r");
$done = 0;
if ($handle) {
while (($line = fgets($handle)) !== false) {
$entry = $parser->parse($line);
$data->save_log($entry);
$done++;
}
fclose($handle);
} else {
echo "An error occurred: unable to open the file!\n";
}
} catch (Exception $e) {
echo 'An error occurred: ' . $e->getMessage() . "\n";
}
echo "Script executed\n";
$ru = getrusage();
echo $footer;
echo "Computations \t:" . $data->rutime($ru, $rustart, "utime") .
" ms\n";
echo "System calls \t:" . $data->rutime($ru, $rustart, "stime") .
" ms\n";
echo "Total lines \t:" . $done . "\n";
echo $footer2;