title: Read through huge text files and store each line in database
body: <p>I wrote a PHP script which runs through a text file (actually it's a 'list' file from imdb) and stores it on my local MySQL database.</p>
  
  <pre><code>public static function updateMovies( $list ) {
      $offset = 15;               // movies.list start with movie names at line 16
      $handle = fopen($list, "r") or die("Couldn't get handle");
      if ($handle) {
          while (!feof($handle)) {
              $buffer = fgets($handle);
              if($offset!=0)
                  $offset--;
              else
                  if($buffer[0] != '"'){
                      $title = trim( substr( $buffer, 0, strpos( $buffer, '(' ) ) );
                      $year = intval(trim( substr( $buffer, strpos( $buffer,'(' )+1, 4 ) ));
                      Movie::create( $title, $year );
                  }
          }
          fclose($handle);
      }
  }
  </code></pre>
  
  <p>Since those list-files are up to 200MB it takes a lot of time. By Default PHP's <code>MAX_EXECUTION_TIME</code> is set to 30 seconds.</p>
  
  <p>I set this value to 300 just to try if it works. For example, my 'movies.list' file is around 80MB and using this script for 300 seconds created around 25000 lines in my database. This doesn't work because I have not even reached the movies starting with 'B'.</p>
  
  <p>I know I can set the <code>MAX_EXECUTION_TIME</code> to 0 (unlimited) but in the future I don't want this database to be on my localhost. I want it on my webserver and my webserver hosts <code>MAX_EXECUTION_TIME</code> is set to 90 as far as I know.</p>
  
  <p>Any ideas how you would handle this?</p>