2

I have log files more than 10GB. each line of a file start with date and time like

2014-12-12 18:17:56 xxxxxxxxxxxxxxxxxxxxxxxxxx
2014-12-12 18:17:57 xxxxxxxxxxxxxxxxxxxxxxxxxx
2014-12-12 18:17:58 xxxxxxxxxxxxxxxxxxxxxxxxxx

2014-12-21 18:17:57 xxxxxxxxxxxxxxxxxxxxxxxxxx
2014-12-21 18:17:57 xxxxxxxxxxxxxxxxxxxxxxxxxx
2014-12-21 18:17:58 xxxxxxxxxxxxxxxxxxxxxxxxxx
2014-12-21 18:17:59 xxxxxxxxxxxxxxxxxxxxxxxxxx

I want read and view the logs for a period example from start-date-time(2014-12-12 18:17:57) to end-date-time(2014-12-21 18:17:58)

I can explode file into array and do the task, but I need best solution with less memory usage.

Please help me on it

Thanks in advance

user3785931
  • 47
  • 1
  • 7

1 Answers1

1

4096 size in bytes to load into memory Example:

<php    
$handle = fopen("/logfile.log", "r") or die("Couldn't get handle");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        //Process buffer here..
    }
    fclose($handle);
}

?>

Reading very large files in PHP

Community
  • 1
  • 1
Buse Gönen
  • 238
  • 1
  • 5