Produce statistical summary of web server log files
<p>A small site uses log file rotation to produce a separate web server log file for each month.
I need to write a PHP script that examines the data in the log files and produces a
single short summary HTML page containing the usage statistics for all months. I have two sample web server log files for 2 months. The statistical summary should contain:</p>

<ol>
<li>The total number of file requests in the month</li>
<li>The number of file requests from the articles directory</li>
<li>TOTAL bandwidth consumed by the file requests over the month</li>
<li>The number of requests that resulted in 404 status errors.</li>
</ol>

<p>Thus far the below code opens the directory files, but I am stuck to produce the stats, any suggestions please? </p>

<p><strong>Sample log file</strong></p>

<pre><code>118.83.4.180 -- [2007-05-01 00:43:38] "GET docs/php_class_syntax HTTP/1.0" 200 10035 "Mozilla/4.0"
20.60.92.212 -- [2007-05-01 01:27:16] "GET docs/regex_crib_sheet HTTP/1.0" 200 12901 "Mozilla/4.0"
133.226.169.34 -- [2007-05-01 02:10:55] "GET not/available HTTP/1.0" 404 0 "Mozilla/4.0"
22.247.135.0 -- [2007-05-01 02:54:33] "GET reference/php_syntax HTTP/1.0" 200 8467 "Mozilla/4.0"
249.33.56.182 -- [2007-05-01 03:38:11] "GET index.php HTTP/1.0" 200 3836 "MSIE 7.0"
124.211.253.106 -- [2007-05-01 04:21:49] "GET articles/dynamic_images_with_php HTTP/1.0" 200 13037 "MSIE 7.0"
</code></pre>

<p><strong>PHP code</strong></p>

<pre><code>&lt;?php

// Open log file
$directory = 'files';

if($handle = opendir($directory.'/')) {
    echo 'These files contains  \' '.$directory.'\':&lt;br/&gt;';

    while(false !== ($file = readdir($handle))) {

        if($file!='.'&amp;&amp;$file!= '..') {
            echo '&lt;a href ="'.$directory.'/'.$file.'"&gt;'.$file.'&lt;br/&gt;';
        }
    }
}
?&gt;
</code></pre>
