title: Fastest way to read a csv file
body: <p>I'm looking for a very fast method to read a csv file. My data structure looks like this: </p>
  
  <pre><code>timestamp ,float     , string    ,ip          ,string
  1318190061,1640851625, lore ipsum,84.169.42.48,appname
  </code></pre>
  
  <p>and I'm using fgetcsv to read this data into arrays.</p>
  
  <p>The problem: Performance. On a regular basis the script has to read (and process) more than 10,000 entries.</p>
  
  <p>My first attempt is very simple:</p>
  
  <pre><code>//Performance: 0,141 seconds / 13.5 MB
  
  while(!feof($statisticsfile)) 
      {
      $temp = fgetcsv($statisticsfile);
      $timestamp[] = $temp[0];
      $value[] = $temp[1];
      $text[] = $temp[2];
      $ip[] = $temp[3];
      $app[] = $temp[4];
      }
  </code></pre>
  
  <p>My second attempt:</p>
  
  <pre><code>//Performance: 0,125 seconds / 10.8 MB
  
  while (($userinfo = fgetcsv($statisticsfile)) !== FALSE) {
     list ($timestamp[], $value[], $text, $ip, $app) = $userinfo;
  }
  </code></pre>
  
  <ol>
  <li>Is there any way to improve performance even further, or is my method as fast as it could get?</li>
  <li>Probably more important: Is there any way to define what columns are read, e.g. sometimes only the timestamp, float columns are needed. Is there any better way than <em>my way</em> (have a look at my second attempt :)</li>
  </ol>
  
  <p>Thanks :)</p>