Problem beim Log-Dateien einlesen..

Alles, was PHP betrifft, kann hier besprochen werden.

Problem beim Log-Dateien einlesen..

Postby Heini_net » 06. October 2004 11:24

Hi leutz..

Ich hab ein Script gebastelt, was die apache log dateien einließt, was jedoch schon länger her ist.. wenn ich es jedoch die access.log einlesen will in der sich viele einträge befindet dauert es bei meiner Prozedur recht lange und es kommt dann zu nem abbruch ( weil womutlich die zeit abgelaufen ist )

weiss einer was man dran optimieren kann ? : hier der code :

Code: Select all
<? 
  if(substr($HTTP_USER_AGENT,0,12)=="Mozilla/4.0 " && $SERVER_PROTOCOL=="HTTP/1.1")
  {
      Header("Content-Encoding: gzip");ob_start();
  }
   
  echo "<INPUT TYPE = \"button\" VALUE = \"     Access    \" onClick =\"window.location.href='?access'\">"; 
  echo "<INPUT TYPE = \"button\" VALUE = \"     Error     \" onClick =\"window.location.href='?error'\">"; 
  echo "<INPUT TYPE = \"button\" VALUE = \"   PHP-Error   \" onClick =\"window.location.href='?phperror'\">"; 
   
   
  switch($QUERY_STRING) 
  { 
       case "access": 
           Header("Content-type: text/html"); 
           echo '<pre>'; 
           echo htmlentities(file_get_contents("C:/xampp/apache/logs/access.log"));
           echo '</pre>'; 
           break; 
      case "error": 
           Header("Content-type: text/html"); 
           echo '<pre>'; 
           echo htmlentities(file_get_contents("C:/xampp/apache/logs/error.log"));
           echo '</pre>'; 
           break; 
      case "phperror": 
           
      if (file_exists('C:/xampp/apache/logs/phperror.log')){
      Header("Content-type: text/html"); 
           echo '<pre>'; 
           echo htmlentities(file_get_contents("C:/xampp/apache/logs/phperror.log"));
           echo '</pre>';
      } else { echo "<p>Datei nicht Vorhanden.</p>"; } 
  } 
 
  if(substr($HTTP_USER_AGENT,0,12)=="Mozilla/4.0 " && $SERVER_PROTOCOL=="HTTP/1.1")
  {
      $r=ob_get_contents();
      $r=str_replace("</body>","<!-- GZip Encoded //--!></body>",$r);
      ob_end_clean();
      echo gzencode($r,9);
  }
 
?>


Mfg. Heini
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

Postby Wiedmann » 06. October 2004 12:32

Hmm, Code macht ja sonst nicht viel, also wird der Abbruch ja beim Einlesen mit file_get_contents() kommen? Oder braucht der htmlentities() so lange? Ausser heraufsetzten des Limits, verkleinern der access.log wird das mit Codeoptimieren schwierig sein... Selbst das Zeileweise einlesen und ausgeben dürfte das wohl eher langsamer machen.

Schau dich doch mal nach "mod_view" um.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby Heini_net » 06. October 2004 13:23

wo kriegt man mod_view für Apache2.0(win32) her ? hab nur ne linux version gefunden..

Mfg. Heini
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

Postby Wiedmann » 06. October 2004 13:44

mod_view: module useful for viewing logfiles
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby Heini_net » 06. October 2004 13:59

cool. danke für die schnelle hilfe..

Mfg. Heini
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

problemchen..

Postby Heini_net » 06. October 2004 15:03

hi..

also ich habs manuell installiert und er findet irgendwie den alias logs nicht..

Zuerst habe ich die so datei in den module ordner geschoben und anschließend folgende einträge in der httpd.conf hinzugefügt bzw. verändert :

Code: Select all
LoadModule view_module modules/mod_view.so

<IfModule mod_view.c>
    # Map a URI to some where else in the file system.
    Alias /logs c:/xampp/apache/logs
    # When the resulting pathanme matches, check for special query
    # arguments. The combination of these two directives allows for
    # a URL like:
    #
    #   http://www.snert.com/log/error_log?tail=20&refresh=15
    #
    # View a URI to some where else in the file system.
    # Only view access_log, error_log, php.log, but not
    # suexec_log, ssl_request_log, etc. and other files
    # within /apache/logs.
    AliasMatch "c:/xampp/apache/logs/(access|error|php)([._]log)?" "c:/xampp/apache/logs/$1$2"
    <Directory c:/xampp/apache/logs>
        ViewEnable on
        AuthName "Benutzer Authentisierung"
   AuthType Basic
   require group Admin
            </Directory>
</IfModule>

nachdem ich dann apache neugestartet hab und den link / logs aufgerufen hab, kommt zwar das htaccess anmelde feld.. beim bestätigen der eingabe kann er dann jedoch die seite nicht finden und folgendes wird in die error log geschrieben :

[Wed Oct 06 16:01:28 2004] [error] [client xxx.xxx.xxx.xxx] Directory index forbidden by rule: C:/xampp/apache/logs/
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

Postby Wiedmann » 06. October 2004 15:22

Dein Alias stimmt so auch nicht:

so könnte es z.B. gehen:
Code: Select all
LoadModule view_module modules/mod_view.so
<IfModule mod_view.c>
   AliasMatch "/log/(access|error|phperror|sslaccess.log|sslerror)([.]log)?" "C:/xampp/apache/logs/$1$2"
   <Directory "C:/xampp/apache/logs">
      ViewEnable on
      Order Allow,Deny
      Allow from all
   </Directory>
</IfModule>
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby Heini_net » 06. October 2004 16:01

hi. also nu hab ich den selben effekt wie als würd ich die datei direkt aufrufen.. wenn se aber 10 mb groß ist scheiterts dann genau wie bei meinem script..

Mfg. Heini
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

Postby Wiedmann » 06. October 2004 17:42

Hmm, hat zwar jetz bei der 10MB-Datei bei mir ewig gedauert.... aber es ging.

lass dir doch einfach nur die letzten x Zeilen anzeigen:
http://localhost/log/access.log?tail=50
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby Heini_net » 06. October 2004 17:55

jeep. da funzt es.. nachteil ist nur das sich bei mir das notepad fenster öffnet anstatt den inhalt im browser anzuzeigen
User avatar
Heini_net
 
Posts: 520
Joined: 25. July 2003 15:43
Location: hier

Postby Wiedmann » 06. October 2004 18:03

Dann musst du noch ein anderes Prblem haben *g*

Das wird ja als "text/plain" ausgeliefert. Und dafür sollte jeder Brower sich selbst zuständig fühlen...

(tut bei mir jedenfalls mit Firefox und IE)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests