Today's Log Hits

 
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions
View previous topic :: View next topic  
Author Message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Mon Jan 29, 2007 2:28 am    Post subject: Today's Log Hits Reply with quote

I thought I might share this script that I created. It shows the logfile hits just from the current day.

You can grab the script here --> http://stephen.calvarybucyrus.org/redirect.php?code=today_logfile
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Mon Jan 29, 2007 4:26 am    Post subject: Reply with quote

I recommend sending the Log File in a Buffer instead of using the file() function. Simply read it in a loop line after line.
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Mon Jan 29, 2007 11:13 pm    Post subject: Reply with quote

TRUSTAbyss wrote:
I recommend sending the Log File in a Buffer instead of using the file() function. Simply read it in a loop line after line.


Are you saying to input the file in a string rather than an array? Or incremental reads?

I'm thinking performance by using the file function. Processing 17276 lines in my logfile took only 0.404 seconds using this script. (1.2 gHz AMD CPU)

What would be the advantage of your method?
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Mon Jan 29, 2007 11:48 pm    Post subject: Reply with quote

My method would use less Memory because you aren't loading the Log File all at once.

Example:

Code:
<?php
$file = array();

// Open the Log File for Read Only
$fp = fopen("C/Program Files/Abyss Web Server/log/access.log", "r");

while (!feof($fp)) {
   
    set_time_limit(0); // Reset Execution time just in case

    $buffer = fgets($fp, 1024);
    $file[] = $buffer; // Add each line to the $file array
}
fclose($fp);
?>


This code adds each line from your log file to the $file array instead of loading everything at once. Loading everything at once causes memory problems. Note: You could turn this whole piece of code into a safer file() Function.

Using this code produces the same results as the file() function, but does it in a buffer.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group