title: How to make PHP run faster?
body: <p>I'm currently trying to import around 20 million rows of data from a textfile to table. The speed of it is far too slow (plus 20 million isn't the full thing).</p>
  
  <p>Any ways of actually making the process go faster? BTW i run it from phpmyadmin... </p>
  
  <pre><code>&lt;?php 
  
  //connection to the database
  $dbhandle = mysql_connect($hostname, $username, $password) 
    or die("Unable to connect to MySQL");
  echo "Connected to MySQL&lt;br&gt;";
  
  $selected = mysql_select_db("data",$dbhandle) 
    or die("Could not select data");
  
  $handle = fopen ('text.txt', 'rt');  
  while (!feof ($handle))  
  {  
      ini_set('max_execution_time',10800);
      $buffer = fgets($handle, 4096);
  
      list($a,$b,$c)=explode(" ",$buffer);
      $lol = explode(".",$c);
      $rest = substr($c,-5,3);
      $date = date('Y-m-d H:i:s');
  
  
      if($rest == 'COM'){
      echo $a." | ".$b." | ".$c."&lt;br&gt;";
      $sqlquery = "INSERT INTO zonenet (date, domainname, dnstype, nameserver) VALUES('".$date."','".$a."','".$b."','".$c."')";   
      mysql_query($sqlquery,$dbhandle) or die(mysql_error());
      } 
      else {
      //$dnstype = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".",
  //          "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
      $str = str_replace($lol[1],".NET",$lol[1]);
      //$str = str_replace(end($lol),".NET",end($lol));
      echo $a." | ".$b." | ".$lol[0]."".$str."&lt;br&gt;";
      $sqlquery = "INSERT INTO zonenet (date, domainname, dnstype, nameserver) VALUES('".$date."','".$a."','".$b."','".$lol[0]."".$str."')";  
      mysql_query($sqlquery,$dbhandle) or die(mysql_error());
      }
      //dnstype reference @http://en.wikipeda.org/wiki/List_of_DNS_record_types
      $sqlquery1 = "DELETE FROM zonenet WHERE dnstype NOT IN ('A', 'AAAA', 'AFSDB', 'APL', 'CAA', 'CERT', 'CNAME', 'DHCID'`enter code here`, 'DLV', 'DNAME', 'DNSKEY', 'DS', 'HIP', 'IPSECKEY', 'KEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'PTR', 'RRSIG', 'RP', 'SIG', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TA', 'TKEY', 'TLSA', 'TSIG', 'TXT')"; 
          mysql_query($sqlquery1,$dbhandle) or die(mysql_error()); 
  
  }   
  fclose ($handle); 
  
  //close the connection
  mysql_close($dbhandle);
  
      //$net=explode(".",$c);
      //echo $a."-".$b."-".$c."&lt;br&gt;";
      //
  
      //
      //mysql_query($sqlquery,$dbhandle) or die(mysql_error()); 
  ?&gt; 
  </code></pre>