문제

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;
}

?>

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top