Jump to content

DanSgt

New Members
  • Posts

    1
  • Joined

  • Last visited

DanSgt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I am having a little trouble with a web server log file and wondered if anyone could give any advice? I currently have the code below: it opens the April log file, explodes it into an Array (text_line_array). I can echo each key in the array to show for example the bandwidth[5], as below, this gives me the 1000 entries of bandwidth looped through but after that I can't figure out how to add these sums together. I can not seem to get the syntax right that allows me to do a loop on an array? A snippet of the log file is below: 103.239.234.105 -- [2007-04-01 00:42:21] "GET articles/learn_PHP_basics HTTP/1.0" 200 12729 "Mozilla/4.0" 207.3.35.52 -- [2007-04-01 01:24:42] "GET index.php HTTP/1.0" 200 11411 "Mozilla/4.0" 51.4.190.113 -- [2007-04-01 02:07:04] "GET articles/php_classes_and_oop HTTP/1.0" 200 7674 "MSIE 7.0" 216.134.52.171 -- [2007-04-01 02:49:25] "GET articles/learn_PHP_basics HTTP/1.0" 200 12729 "MSIE 7.0" 97.212.128.181 -- [2007-04-01 03:31:46] "GET articles/using_regex_with_php HTTP/1.0" 200 12127 "Mozilla/4.0" 49.174.77.138 -- [2007-04-01 04:14:07] "GET about/contact.php HTTP/1.0" 200 7554 "Mozilla/4.0" 219.218.151.127 -- [2007-04-01 04:56:28] "GET reference/mysql_crib_sheet HTTP/1.0" 200 11109 "MSIE 7.0" 209.168.87.74 -- [2007-04-01 05:38:49] "GET articles/mysql_load_bala.0"ncing HTTP/1.0" 200 3189 "MSIE 7.0" 79.214.145.94 -- [2007-04-01 06:21:11] "GET articles/mysql_load_balancing HTTP/1.0" 200 3189 "MSIE 7.0" 177.158.203.244 -- [2007-04-01 07:03:32] "GET docs/regex_crib_sheet HTTP/1.0" 200 12439 "Mozilla/4" This is what I have so far: $handle = fopen('logs/april.log', 'r'); while (!feof($handle)) { $text_line = fgets($handle, 1024); $notNeeded = array(' --','[',']','GET ',' HTTP/1.0'); $text_line = str_replace($notNeeded,NULL,$text_line); $text_line_array = explode(' ',$text_line); $ipAddress = $text_line_array[0]; $timestamp1 = $text_line_array[1]; $timestamp2 = $text_line_array[2]; $filename = $text_line_array[3]; $statusCode = $text_line_array[4]; $bandwidth = $text_line_array[5]; $userAgent = $text_line_array[6]; } Do you have any ideas? I am trying to write a summary which displays: the total amount of requests, the total amount of requests form the articles directory, the total bandwidth consumed and finally the amount of 404 errors and their pages.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.