title: Reading large files from end
body: <p>Can I read a file in PHP from my end, for example if I want to read last 10-20 lines?</p>
  
  <p>And, as I read, if the size of the file is more than 10mbs I start getting errors. </p>
  
  <p>How can I prevent this error?</p>
  
  <p>For reading a normal file, we use the code :</p>
  
  <pre><code>if ($handle) {
      while (($buffer = fgets($handle, 4096)) !== false) {
      $i1++;
      $content[$i1]=$buffer;
      }
      if (!feof($handle)) {
          echo "Error: unexpected fgets() fail\n";
      }
      fclose($handle);
  }
  </code></pre>
  
  <p>My file might go over 10mbs, but I just need to read the last few lines. How do I do it?</p>
  
  <p>Thanks</p>