Hi there guys;
I was wondering if anyone could give me a little help i have a script that opens a file and returns the total files requested, the total files requests in the articles directory, the total bandwidth used, the total 404 Errors and the files the produced those errors, the problem is it only opens 1 file and i need it to open 2 or 3 or even more files and return the same data but with the code that i have if i want to open 2 or 3 files i will have to duplicate the code which is not the best aproach i also know that the best solution would be to store the files in a directory and use opendir instead of fopen, i've tried to implement the opendir but i just cant get it to work, here is the current code:
<?php
// Opens the folder in the reading mode
$fileLog = fopen("may.log", "r");
// Variable to count the total bytes used during the month
$totalBytes = 0;
// Variable to count the total files requested during the month
$linecount = 0;
$file_requested = 0;
// Variable to count the total errors found
$file_not_found = 0;
// Variable assigned to array that stores and displays the description of the errors found
$errors = array();
$articles_file = 0;
// While not the end of file get and echo the data line by line
while (!feof($fileLog)) {
$line = fgets($fileLog, 1024);
$linecount = $linecount + substr_count($line, "\n");
// Explodes the data with a space
$details = explode(' ', $line);
// Checks if the variable is set if yes returns true if no returns an Notice on the site
if (isset($details[8]))
// Adds all the bytes and stores them in $totalBytes
$totalBytes = $totalBytes +$details[8];
if (isset($details[7]))
if ($details[7] == "404") {
$file_not_found++;
if(!in_array($details[5], $errors)) {
$errors[] = $details[5];
}
}
if (isset($details[5]))
$directory_string = $details[5];
$directory_array = explode("/",$directory_string);
if($directory_array[0] == "articles") {
$file_requested++;
}
}
fclose($fileLog);
// Assigns the variable $totalBytes to $total and rounds it up to 7 decimal places
$total = round(($totalBytes/1000000),2);
// Adds commas every 3 digits
$totalBytes = number_format($totalBytes);
echo "<h3>May Statistics</h3>";
// Echoes the variable $linecount
echo "<p>The Total files requested: $linecount </p>";
echo "<p>Total files requests the articles directory: $file_requested </p>";
// echoes the total bytes
echo "<p>The Total bandwidth used: $total MB ($totalBytes Bytes)</p>";
// Echoes the the variable $file_not_found
echo "<p>Total 404 Errors: $file_not_found </p>";
echo "<p>The following files produced errors:</p>";
// Assigns the variable $errors to $error and echoes the result in a unordered list
echo "<ul>";
foreach ($errors as $error) {
echo "<li>$error</li>";
}
echo "</ul>";
?>
Any examples on how to do it, ideas, or suggestions will be more then welcome thank you guys.