开发者

Fgets stops after 130 lines PHP

开发者 https://www.devze.com 2023-03-17 12:17 出处:网络
$done=0; $filename = \"raw_urls.txt\"; if(! ($fhandle = fopen($filename, \"r\"))) { echo \"File failed to open\";
    $done=0;
    $filename = "raw_urls.txt";
    if(! ($fhandle = fopen($filename, "r")))
{ echo "File failed to open"; 
    Exit; }
    //
    //  main loop reads sitemap url list
    //
    whi开发者_JAVA百科le($url_full_raw = fgets($fhandle,4096))
    {
    print (mysql_error());

$url_full= preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $url_full_raw);
if(strlen($url_full) > 3)
{
    $url_stat++;
    //  Echo ' tp1 Url from sitemap:',$url_stat,' - ' ,$url_full,'<br>';
    $end_st = strlen($url_full)-29;
    $s_url= substr($url_full,29,$end_st);
    //Echo 'short:',$s_url,'<br>';
    $url_full_raw= '';
}
else{
    $done++;
    Echo '----------- short string ---------------';
}
//
//        Check for url
//
$res1=sql("SELECT * FROM `spy3` WHERE `Landingpage` LIKE '%$s_url%' LIMIT 0, 30 ",$o);
if($row=mysql_fetch_array($res1))
{
    $lp=$row[6];
    $found++;
    //  Echo '------->Url from sitemap:',$url_full,'<br>';
}
else{
    Echo 'Not Found:-> ',$s_url,'<br>';
    $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;

}

So the code works great. Except for one problem, after about 130 lines, it stops. It exits the program with no error. Yes full error reporting is on. PHP.ini memory is huge. If I edit the txt file and take out some lines, no difference. I have been working on this for many hours.


Try doing it like they do in their example... with !== false. i.e,

while(($url_full_raw = fgets($fhandle,4096))!==false) {

I'm guessing your content is evaluating to false for whatever reason. That just happens to be at 130 lines (throw the 130 lines into a text file and see if the file size is close to 4 KB).

Also, you might want to fix your formatting for next time. Makes it very hard for us to read and help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消