title: Efficiently counting the number of lines of a text file. (200mb+)
body: <p>I have just found out that my script gives me a fatal error:</p>
  
  <pre><code>Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 440 bytes) in C:\process_txt.php on line 109
  </code></pre>
  
  <p>That line is this:</p>
  
  <pre><code>$lines = count(file($path)) - 1;
  </code></pre>
  
  <p>So I think it is having difficulty loading the file into memeory and counting the number of lines, is there a more efficient way I can do this without having memory issues?</p>
  
  <p>The text files that I need to count the number of lines for range from 2MB to 500MB. Maybe a Gig sometimes.</p>
  
  <p>Thanks all for any help.</p>