title: Start Parsing CSV File On Line "X"
body: <p>I'm working on a CSV upload that has 35,000 lines of stuff going on and I'm trying to think of a way to start my parsing of the CSV file at line "X". I've been refreshing the page and saving the line I was last on each time so it would fix the timeout issue I was having with browsers. Now, I just need to know how to start my CSV file on that line I left off.</p>
  
  <pre><code>while(($data = fgetcsv($handle, 0, ",")) !== false) {
      if($i &gt; 2000) { break; }
      //start parsing here
      $i++
  }
  $_SESSION['lastLine'] = $i;
  $_SESSION['filepath'] = $filepath;
  //resend headers
  </code></pre>
  
  <p>I save the filepath as a session as well because it's been uploaded to a temporary folder and I can re-access it. So the first time I upload, I go through all 2000 lines perfectly happy. The headers reset and start the process again, but since $_SESSION['lastline'] is now 2001, the code breaks (which is fine). What I need to figure out is how can I start my parsing on line 2001 and break again on 4000. This will continue until all 35,000 lines are done.</p>
  
  <p>I was thinking about setting the break statement before the parsing to say:</p>
  
  <pre><code>if($i &lt; $_SESSION['lastLine']) { $i++; }
  if($i &gt; $_SESSION['lastLine'] + 2000) { break; }
  </code></pre>
  
  <p>My problem is, doing 35,000 lines of CSV means that the last 10 or so runs will have to do an i++ loop thousands of times before the parsing even begins. I looked around for some ways to just start the CSV file at line "X", which would be my preferred method of doing this, but I couldn't find anything. Any help would be awesome.</p>