0

i have a huge file, going upto 10 MB.

I want to load the file using php in chunks. Also the file should be loaded in reverse order.

what i want to do is, provide a to and from file pointers or byte sizes where 0 means the last position of the file.

so if i say

0 - 5000, it would mean load from position : last -5000 to last

5000 - 10000, it would mean load from position : last - 10000 to last - 5000

Nauman Bashir
  • 1,732
  • 3
  • 18
  • 26
  • i dont want to use file() and then use array_chunk , because that seems to be extensive, what i want is to only load parts of files provided by the two pointers – Nauman Bashir Dec 07 '11 at 13:57

1 Answers1

0

This may work for you?

//opens file
$ctx = fopen('file.txt', 'r');

//number of lines from end to read
$number = 5000;

//move to end of file - $number
fseek($ctx, $number, SEEK_END);

//loop until end of file
while(!feof($ctx))
{
    $buffer = fgets($ctx);
}

fclose($ctx);
Jason Brumwell
  • 3,482
  • 24
  • 16