Jump to content


Warning Messages! Help


8 replies to this topic

#1 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 11 May 2006 - 04:38 AM

I've got a peice of php code that pulls a Guild Ladder result from the website www.guildwars.com. The code is as follows:

<?PHP
$streamSource = fopen("http://ladder.guildwars.com/ladder.dll?name=War+Masters","r");
$write = 0;
$ladder=0;
while(!feof($streamSource)){
$buffer = trim(fgets($streamSource,5000));
if(trim($buffer) == "<!-- FIELDS HEADERS -->"){$write = 1;}
if(strlen($buffer)>50){
$templen=strlen($buffer)-11;
$buffer=substr($buffer,0,$templen);
}
if(trim($buffer) == "<p>"){$write = 0;}
if($write == 1){
echo $buffer;
$ladder=1;
}
}
fclose($streamSource);
if($ladder==0){echo "<h1>War Masters Guild does not presently rank on the Guild Ladder</h1>";}
?>

The code has worked fine previously, however I now get this error message when I visit my site:

WarMaster Guild

And I don't know why? It looks as though its stuck in a loop. Can anyone help?

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 11 May 2006 - 08:58 AM

sorry but what error message? i dont see one

#3 Erik Bernskiold

    Jedi In Training

  • Members
  • PipPip
  • 422 posts
  • Gender:Male
  • Location:Gothenburg, Sweden
  • Interests:I love to do booth Web Design and Photography. Nothing beats a nice day out in the nature with the camera gear, getting loads of nice photos. I have been playing the flute for 6 years now and I love it, and I am playing the pipe organ as well. I also like to teach other people the in and outs of software such as the CS3 suite from Adobe.

Posted 11 May 2006 - 09:15 AM

I don't see any error message either...

#4 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 11 May 2006 - 10:50 AM

Try This This is a page on the site using the exact same code.

Edited by MKayHavoc, 11 May 2006 - 11:06 AM.


#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 May 2006 - 04:34 PM

I don't see any error either. Could you please post the error that you're seeing, or take a screenshot of it?

#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 11 May 2006 - 04:40 PM

well from the page it says error on live 45, thats all, and we dont know which is line 45 from tht piece of code

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 May 2006 - 04:58 PM

Well, i just rechecked myself,, and i got this error:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /home/www/warmastersguild.awardspace.com/index.php on line 47
When i refreshed, it was gone, and it took a couple of refreshes to get the error again.

To fix this, you could try changing all lines that deal with fopen() to something like:
$streamSource = @fopen("http://ladder.guildwars.com/ladder.dll?name=War+Masters","r");
if(!is_resource($streamSource)){
	// there was an error
}else{
	// continue executing code
}


#8 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 12 May 2006 - 02:45 AM

Looking at it this morning, it appears that when you first go to the page it throws up an error, like it's trying to display the information too quickly. A coupld of refreshes seems to fix it. Is there a wait command in PHP something like:

$streamSource = @fopen("http://ladder.guildwars.com/ladder.dll?name=War+Masters","r");

WAIT 5 secs

Continue with code?

And then put in rc69's suggestion to display an error message if this still fails.

Many Thanks

#9 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 12 May 2006 - 02:58 AM

View PostMKayHavoc, on May 12 2006, 08:44 AM, said:

Looking at it this morning, it appears that when you first go to the page it throws up an error, like it's trying to display the information too quickly. A coupld of refreshes seems to fix it. Is there a wait command in PHP something like:

$streamSource = @fopen("http://ladder.guildwars.com/ladder.dll?name=War+Masters","r");

WAIT 5 secs

Continue with code?

And then put in rc69's suggestion to display an error message if this still fails.

Many Thanks

I've just tried a sleep(5); command. With no joy.

I think I need to create a loop that doesn't continue with the rest of the code until it gets a response. Code is as follows:

<?PHP
$streamSource = fopen("http://ladder.guildwars.com/ladder.dll?name=War+Masters","r") or die( "Unable to connect to the ladder");
$write = 0;
$ladder=0;
while(!feof($streamSource)){
$buffer = trim(fgets($streamSource,5000));
if(trim($buffer) == "<!-- FIELDS HEADERS -->"){$write = 1;}
if(strlen($buffer)>50){
$templen=strlen($buffer)-11;
$buffer=substr($buffer,0,$templen);
}
if(trim($buffer) == "<p>"){$write = 0;}
if($write == 1){
echo $buffer;
$ladder=1;
}
}
fclose($streamSource);
if($ladder==0){echo "<h1>War Masters Guild does not presently rank on the Guild Ladder</h1>";}
?>

Edited by MKayHavoc, 12 May 2006 - 04:01 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users