Reputation: 972
I have a folder called awstats
which contains all the log files for each month, I need to parse all of them and get content for all the files at the same time
I tried this :
$filename = DOCUMENT_ROOT."sites/".HOSTNAME."/awstats/".$_SESSION['awstat_month'].$_SESSION['awstat_year']."."HOSTNAME".txt";
if(file_exists($filename))
$awstats = file_get_contents($filename) ;
else {
print_warning("the log file does not exist!");
return;
}
But it only parse a log file at the time. Is there a way to parse all the log file at the same time and get a certain content for each file? Much Appreciated!
Upvotes: 0
Views: 137
Reputation: 51
You should in some way iterate over those statistic files. It seems those variable parameters are @ $_SESSION['awstat_mont'] and $_SESSION['awstat_year'] so a naive solution would be a double foreach loop: (I am assuming you are using php so have a look over here: http://de3.php.net/manual/en/control-structures.foreach.php)
foreach ($allYearsToCheck as $year) {
foreach ($allMonthToCheck as $month) {
$filename =DOCUMENT_ROOT."sites/".HOSTNAME."/awstats/".$month.$year."."HOSTNAME".txt";
if(file_exists($filename)){
$awstats .= file_get_contents($filename) ;
}
else {
print_warning("the log file does not exist!"
}
}
}
where allMontToCheck and allYearsToCheck are arrays containig all years and month you would like to check. $awstats will contain all logfiles concatenated.
Upvotes: 1