Search code examples
phpfgetsscanf

Fscanf stops after 130 lines PHP


I have been working on this for days, I thought I had it but was wrong.

    $done=0;
    $filename = "raw_urls.txt";
    if(! ($fhandle = fopen($filename, "r")))
    { echo "File failed to open"; 
         Exit; }
    while((fscanf($fhandle, "%s\n",$url_full))!== false)
     {     
       print (mysql_error());

     if(strlen($url_full) > 3)
     {
        $url_stat++;
        $end_st = strlen($url_full)-29;
        $s_url= substr($url_full,29,$end_st);
        }
     else{
         $done++;
         }

     $res1=sql("SELECT * FROM `spy3` WHERE `Landingpage` LIKE '%$s_url%' LIMIT 0, 30 ",$o);
     if($row=mysql_fetch_array($res1))
        {
         $lp=$row[6];
         $found++;  
        }
       else{
        $nfound++;
        }


sql("insert into sitemap (url, stat_url,nf, s_recno) 
values (
'$url_full',
'$lp',
'$nfound',
'$url_stat'
)", $o);
print (mysql_error());
$found=0;
$nfound=0;
}

?>

I have tried fgets, changed txt files, it always stops between 128 and 132 lines of text. There are 2500 lines in the text file. Php.ini memory is very big. If I cut the txt file where it stops and save it, its 9k big.


Solution

  • have seen this link..?

    Please Click here

    OR

    you can also use fseek($handle, 0); AND refer this link

    Thanks.