Question

This function is pretty generic its intended to parse a txt file that is delimited with a tab, the files im trying to parse is geonames database, it tops out at 1953146 results every time and from which point nothing happens at all, no more querys and doesnt exit, counting the lines i can see there is 8,000,000 lines in the file so im guessing it is stalled, errors are enabled and there is no error returned php_memory is set to 2048M execution time is set to unlimited.

<?php

function table_populate($table,$file,$columns){
    $handle = fopen($file, "r");
    $lines = count(explode("\n",file_get_contents($file)));
    $i = 0;
    while (($line = fgetcsv($handle, 10000, "\t")) !== false && $i < $lines) {
        if(preg_match('[#]',$line['0'])){
          // do nothing row is commented out
        }else{
          $row = '';
          $comma = '';
          for ($z = 0; $z < count($line); $z++) {
            $row .=  $comma."'".$line[$z]."'";
            $comma = ', ';
          }
          $sql = "INSERT INTO ".$table." (".$columns.") VALUES (".$row.")";

        }
        $i++;
    }   
    fclose($handle);
    return;
}

?>

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top