I have a text file (log file) that I want to be able to read the last 30 or
40 lines of.  I've created the code below, but since this file is so large
(currently 8 MB) it won't work.  The code works on smaller files, but not
this one.  Can someone look at this below and tell me where I went wrong?

<?php

$filename ="/var/log/radius.log";

$myFile = fopen($filename, "r"); //open the file for reading, file pointer
will be at the beginning of the file

if(! $myFile){            // Make sure the file was opened successfully

print ("File could not be opened.");

exit;
}

$fcontents = file($filename);

  $limit = 30;

for ($i = 0; $i < $limit; $i++){ // while $i is less than 30

    $line = $fcontents[$i];  // assign value of array element to a variable

      if($line != ""){  // if the line from the file is not blank print it
        echo "$line \n";
          }

     }

fclose($myFile);

?>

Thanks,
Scott Miller



-- 
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.251 / Virus Database: 263.3.2 - Release Date: 6/15/2004

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to