I am trying to to write a PHP script that examines and extracts the data from a log file and produces a statistical summary of the contents: total number of file requests in the month, number of file requests from the articles directory, TOTAL bandwidth consumed by the file requests over the month and the number of requests that resulted in 404 status errors as well as a list of the filenames that produced these 404 errors.
I've managed to extract the file and find out the total bandwidth consumed over the month using the following code:
Code: Select all
<?php
// Opens the file "april" in read mode only
$fileLog = fopen("april.txt", "r");
// Variable to count the total bytes used during the month
$totalBytes = 0;
// While not the end of file get and echo the data line by line
while (!feof($fileLog)) {
$line = fgets($fileLog, 1024);
// Explodes the data with a space
$details = explode(' ', $line);
// Adds all the bytes and stores them in $totalBytes
$totalBytes = $totalBytes +(int)$details[8];
}
// Adds commas every 3 digits
$totalBytes = number_format($totalBytes);
echo "<h3>April Statistics</h3>";
// echoes the total bytes
echo "<p>The TOTAL bandwidth consumed used: 8.43MB ($totalBytes Bytes)</p>";
fclose($fileLog);
?>Any suggestion or example on how to achieve this..please.
Many thanks