Warning Messages! Help
Started by MKayHavoc, May 11 2006 04:38 AM
8 replies to this topic
#1
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?
<?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
Posted 11 May 2006 - 08:58 AM
sorry but what error message? i dont see one
#3
Posted 11 May 2006 - 09:15 AM
I don't see any error message either...
#5
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
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
Posted 11 May 2006 - 04:58 PM
Well, i just rechecked myself,, and i got this error:
To fix this, you could try changing all lines that deal with fopen() to something like:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /home/www/warmastersguild.awardspace.com/index.php on line 47When 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
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
$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
Posted 12 May 2006 - 02:58 AM
MKayHavoc, 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
$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
