Location: PHPKode > projects > Apache Stats > apacheStats_0.0.3Beta/includes/requestTime.inc
<!-- $Id: requestTime.inc,v 1.1.1.1 2007/01/21 12:22:47 ianbezanson Exp $ -->

<?php
  $requestTime = "SELECT time_stamp, request_uri, bytes_sent, remote_host, status, virtual_host, request_duration FROM $chosenServer WHERE ";
  for($i=0; $i<$iter; $i++) $requestTime .= "virtual_host=\"" . $virtHosts[$i] . "\" OR ";
  $requestTime .= "virtual_host=\"" . $virtHosts[$i] . "\" ORDER BY request_duration DESC LIMIT $startPoint, $delim";

  $reqTime = mysql_query($requestTime);

  $finalDisp .= "<center><table class=\"display\"><tr><td class=\"left\">Displaying results ";
  $finalDisp .= $startPoint+1 . " - ";
  if($nextPage > $tHitD) $finalDisp .= $tHitD;
  else $finalDisp .= $nextPage;
  $finalDisp .= " of $tHitD</td><td class=\"right\">Displaying page ";
  $finalDisp .= $thisPage+1 . " of " . $numPages;
  $finalDisp .= "</td></tr></table><br />";


  $finalDisp .= "<table class=\"logView\" cellspacing=\"0\">";
  $finalDisp .= "<tr><td class=\"header\">Date</td><td class=\"header\">Bytes Sent</td><td class=\"header\" colspan=\"2\">URL</td><td class=\"header\">Remote Host</td><td class=\"header\">Status</td><td class=\"header\">Virtual Host</td><td class=\"header\">Load Time</td></tr>";
  while($myrow = mysql_fetch_array($reqTime))
  {

    $getVHost = mysql_query("select longName from $vhostTable where shortName='$myrow[virtual_host]'");
    while($vHostList = mysql_fetch_array($getVHost)) $thisVHost = $vHostList[longName];

    $statusCodes[$myrow[status]]++;
    $requests[$myrow[remote_host]]++;
    $totalBytes += $myrow[bytes_sent];
    $thisBytes = convertSize($myrow[bytes_sent]);
    $thisDuration = secsToText($myrow[request_duration]);
    if($myrow[bytes_sent] > $largestValue)
    {
      $largestValue = $myrow[bytes_sent];
      $largestURI = $myrow[request_uri];
      $host = $thisVHost;
    }
    $thisCountry = strtolower(getCountry($myrow[remote_host]));
    $thisTime = date('d-M-Y h:i:sa', $myrow[time_stamp]);
    $finalDisp .= "<tr><td>$thisTime</td><td>$thisBytes</td><td>";
    if (ereg("4[0-9][0-9]", $myrow[status]) || ereg("5[0-9][0-9]", $myrow[status]) || ereg("302", $myrow[status]))
    {
      $finalDisp .= shortText($myrow[request_uri], 30);
      $finalDisp .= "</td><td>&nbsp";
    }
    else
    {
      $finalDisp .= shortText($myrow[request_uri], 30);
      $finalDisp .= "</td><td>";
      $finalDisp .= "<a target=\"_new\" href=\"$thisVHost$myrow[request_uri]\">[Link]</a>";
    }
    $finalDisp .= "</td><td>";
    if (!$thisCountry) ;
    else
    {
      $finalDisp .= "<img src=\"$flagfolder" . $thisCountry . ".gif\" width=\"18\" height=\"12\">[" . strtoupper($thisCountry) . "]";
    }
    $finalDisp .= " $myrow[remote_host]</td><td>$myrow[status]</td><td>$myrow[virtual_host]</td><td>$thisDuration</td></tr>";
  }
  $totalBytes = convertSize($totalBytes);
  $finalDisp .= "<tr><td class=\"totals\">Total Bytes:</td><td class=\"totals\" colspan=\"7\">$totalBytes</td></tr>";
  $finalDisp .= "</table><br />";

  $finalDisp .= multiPageDisplay('4',$thisPage,$tHitD,$numPages,$prevPage,$nextPage,$linkTag,$virtHosts,$delim,$chosenServer,$chooseType,$view,$periodList,$display,$whichDisp);

  $dispCodeInfo .= "<table class=\"logView\" cellspacing=\"0\">";
  $dispCodeInfo .= "<tr><td class=\"header\" colspan=\"4\">Largest File (On This Page): </td></tr>";
  $dispCodeInfo .= "<tr>";
  $dispCodeInfo .= "<td>$host</td>";
  $dispCodeInfo .= "<td>" . shortText($largestURI, 30) . "</td>";
  $dispCodeInfo .= "<td><a target=\"_new\" href=\"$host$largestURI\">[Link]</a></td>";
  $dispCodeInfo .= "<td>" . convertSize($largestValue) . "</td></tr>";
  $dispCodeInfo .= "<tr><td class=\"header\" colspan=\"4\">Error Codes (On This Page): </td></tr>";
  ksort($statusCodes);
  foreach($statusCodes as $key => $value)
  {
    $getCodes = "SELECT status, heading FROM statuscodes WHERE status=\"$key\"";
    $getCodesDesc = mysql_query($getCodes);
    while($codeRow = mysql_fetch_array($getCodesDesc))
    {
      $dispCodeInfo .= "<tr><td>$codeRow[status]</td>";
      $dispCodeInfo .= "<td colspan=\"2\">$codeRow[heading]</td>";
      $dispCodeInfo .= "<td>$value</td></tr>";
    }
  }
  $dispCodeInfo .= "<tr><td class=\"header\" colspan=\"4\">Most Requests (On This Page): </td></tr>";
  $largestVal = 0;
  $largestKey = "";
  foreach($requests as $key => $value)
  {
    if($value > $largestVal)
    {
      $largestVal = $value;
      $largestKey = $key;
    }
  }
  foreach($requests as $key => $value)
  {
    if($value == $largestVal)
    {
      $finalCode = $key;
      $finalCount = $value;
    }
  }
  $dispCodeInfo .= "<tr><td colspan=\"3\">";
  $thisCountry = strtolower(getCountry($finalCode));
  if (!$thisCountry) ;
  else
  {
    $dispCodeInfo .= "<img src=\"$flagfolder" . $thisCountry . ".gif\" width=\"18\" height=\"12\">[" . strtoupper($thisCountry) . "]";
  }
  $dispCodeInfo .= "$finalCode</td><td>$finalCount</td></tr></table>";
?>
Return current item: Apache Stats