0

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.

Joe
  • 335
  • 2
  • 4
  • 12
  • BTW This code does not work from the PHP website: `while (($buffer = fgets($handle, 4096)) !== false) { echo $buffer; }` $buffer is set to a number, the return value of the funtion. – Joe Jul 05 '11 at 12:42
  • You might want to clarify that comment. I'm pretty sure that `fgets` example works. You should probably investigate why it's not working *for you*. – deceze Jul 05 '11 at 12:49
  • Could you expand on "stops"? Does it hang, give an error message..? Have you got error reporting turned on? – Matt Gibson Jul 05 '11 at 12:51
  • @Matt It stops executing. No error messages. Just exits and I can view the file to see the last record read. – Joe Jul 05 '11 at 13:00
  • @deceze, I have been working with fgets for days. fgets on its own returns a string. with the !== false it returns a value. – Joe Jul 05 '11 at 13:01

1 Answers1

0

have seen this link..?

Please Click here

OR

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

Thanks.

Community
  • 1
  • 1
Chandresh M
  • 3,808
  • 1
  • 24
  • 48
  • I have not tried fseek. The file is a variable length so I wanted php to stop at the lf. – Joe Jul 05 '11 at 13:06
  • while ($line = fgets($file)) { echo $line; I did use this also. It also stopped at the same point. – Joe Jul 05 '11 at 13:22
  • Fixed. It was a timeout issue. set_time_limit(0); fixed it. I saw it on one of those links they suggested a timeout. I had the code from another program. So much time on a little program :*( – Joe Jul 05 '11 at 13:34