PHP如何处理大量的时间

I have a 36mb (FILE B) with over 650k lines.I have tried fgets, fopen, file_get_contents and they are not working. I think I am running out of memory. What I am trying to do is, I have file 'A excel (138 lines)', I want to loop thru it get a value and go find (via regex )it in File B (.TXT - 35MB). Once I have found it in 'File B' , I want to take it write it in 'FILE A'. I went into the .ini changed max memory also and the timer (300). fopen() sample below:

$handle = fopen("/Users/jerry/Desktop/info.TXT", "r") or die("Couldn't get handle");
if ($handle) { //IF
    while (!feof($handle)) { //WHILE
        $buffer = fgets($handle, 4096);
        //  echo $buffer; //displays the 650k lines
         for ($row12 = 2; $row12 <= 23; $row12++){ //for1
$name3 = $objPHPExcel45->getActiveSheet()->getCellByColumnAndRow(3, $row12)->getValue() ; 
            $regex144 = "/$name3/";
            preg_match($regex144, $buffer, $try);
            foreach ($try as $h => $wer){//foreach
                echo $wer; echo $row1; echo "<br>";
        //  $nameset = $objPHPExcel45->getActiveSheet()->setCellByColumnAndRow(7, $row12)->getValue() ;
            }//foreach
        }//for 1    
    }//WHILE    
    fclose($handle);
}//IF

File_get_contents option:

$htmlfile = "/Users/deepak/Desktop/info.TXT";
$html1 = file_get_contents($htmlfile);
for ($row3 = 2; $row3 <= 50; $row3++){ 

      $name3 = $objPHPExcel45->getActiveSheet()->getCellByColumnAndRow(3, $row3)->getValue() ; 
//checking for a initial 
        if (preg_match($renamewithinitials, $name3, $matchesini)) { //1st if

    //flip the name with initials
$names5 = explode(" ", $name3);
$name5 = $names5[2] . " " . $names5[1]. " " . $names5[0];   
$length1 = strlen($name5);
$regex1 = "/[0-9]{23}$name5/";
preg_match($regex1, $html1, $t);
foreach($t as $x22 => $x_value22) {
    echo "lets see if works LION INITIAL: $x_value22"; echo "<br>";
}

//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3,$name5);
} //1st if

  // is there a compnay name
     else { //1st else
        if (preg_match($renamewithinitials2, $name3, $matchesini2)) { //2nd if

//NO name flipping
$name6 = $name3;
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name6);
        } //2nd if


     //is there 2 spaces TWO SPACES TWO SPACES ONLY
        else { //2nd else
        if (preg_match($renamewithTwoSpaces, $name3, $matchesini3)) {//3rd if
        //flip name
            $names8 = explode("  ", $name3);
$name8 = $names8[1] . " " . $names8[0];

$regextwospace = "/[0-9]{23}$name8/";

preg_match($regextwospace, $html1, $t2space);
foreach($t2space as $x2234 => $x_value2234) {
    }
//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name8);
        }//3rd if   
        //is there ONE SPACE ONE SPACE ONLY
        else { //3rd else
        if (preg_match($renamewithOneSpace, $name3, $matchesini4)) { //4th if
        //flip name
            $names9 = explode(" ", $name3);
$name9 = $names9[1] . " " . $names9[0];
$regexonespace = "/[0-9]{23}$name9/";
preg_match($regexonespace, $html1, $tonespace);
foreach($tonespace as $x223 => $x_value223) {
}
//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name9);
        }//4th if
        } //2nd else

                        }  //3rd else   
            } //1st else    
}  //for     
//}
fclose($html1);
//we save
$objWriter45->save($auctionFileExplodeFinal[0].'-DRD-FILE-copy-nosave.xlsx');
dongliechuich10319
dongliechuich10319 如果这与grepregex大文件有些相关,并且grep实际上能够处理大文件:也许从PHP调用shell脚本可能是一个选项。
大约 5 年之前 回复
duanqie8549
duanqie8549 你多久会这样做?你基本上使用的是一个平面文件数据库,没关系就可以了。使用36MB文件,您只是在寻找麻烦。如果只有两个人尝试运行此脚本怎么办?在数据库中拥有大型文本数据文件肯定会让您受益匪浅。我强烈建议远离这一思路。
大约 5 年之前 回复
duandou1903
duandou1903 我可以设置的最大内存限制是多少?最大执行时间?
大约 5 年之前 回复
drde3456
drde3456 在大约30的file_get_contents中。上面的Fopen()选项代码不起作用......也许我的编码错了。
大约 5 年之前 回复
doudao1922
doudao1922 文件处理程序选项死在哪一行?
大约 5 年之前 回复
dougu4448
dougu4448 将您的文件转换为数据库
大约 5 年之前 回复
dqmnueuu459279
dqmnueuu459279 在localhost上运行....
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问