View previous topic :: View next topic |
Author |
Message |
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Mon Jan 29, 2007 4:26 am Post subject: |
|
|
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 |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Mon Jan 29, 2007 11:13 pm Post subject: |
|
|
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 |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Mon Jan 29, 2007 11:48 pm Post subject: |
|
|
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 |
|
|
|