title: Codeigniter Allowed memory size exhausted while processing large files
body: <p>I'm posting this in case someone else is looking for the same solution, seeing as I just wasted two days on this bullshit.</p>
  
  <p>I have a cron job that updates the database using a very large file once a day, using the following code:</p>
  
  <pre><code>if (($handle = fopen(dirname(__FILE__) . '/uncompressed', "r")) !== FALSE) 
  {
      while (($data = fgets($handle)) !== FALSE) 
      {
          $thisline = json_decode($data, true);
          $this-&gt;regen($thisline);
      }
      fclose($handle);
  }
  </code></pre>
  
  <p>This is in a Codeigniter controller that's only used for cron jobs. The $this->regen function runs through a bunch of different checks and stores the right information from the line in the database. The file itself is over 300MB of JSONs separated by newlines.</p>
  
  <p><strong>The problem:</strong> it would only process about 20,000 lines before the whole thing ran out of memory.</p>