I assist in running a helpsite for the popular online Java game, www.runescape.com. What brings me here to day is, troubles with looking up data from the highscores for a thing called stats signatures (look up the user's stats, put them on a dynamic image, and save it so they can use the image in their forum signature). Currently to look up data I have to create a new connection to their highscores page (using fsockopen()), write to their page, or rather post to their page, the user's name that I want to lookup, get the data I want, and close it. However, this is for just ONE skill - there are around 21 plus a few other items I grab, such as total level/experience. Aside from massive CPU usage every time it has to do this, the loading time is well over the 8 seconds people are willing to wait for a pageload - it's around a minute. Generating the image takes half a second, so I don't need help with that. I'm quite well with image generation.
Any assistance would be grately appreciated... The following is my lookup code and an example of how I fill the fields.
CODE
<?php
function hsc($finalrsname, $skill, $item)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$skill = strtolower($skill);
$fp = fsockopen("hiscore-web.runescape.com", 80, $errno, $errstr, 30);
if (!$fp) {
die("$errstr ($errno)<br />\n");
} else {
stream_set_timeout($fp,1);
$out = "POST /lang/en/aff/runescape/hiscorepersonal.ws HTTP/1.1\r\n";
$out .= "Host: hiscore-web.runescape.com\r\n";
$out .= "From: admin@runemasters.net\r\n";
$out .= "Content-length: ".(strlen(rawurlencode($finalrsname))+21)."\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: RuneSignatures/1.0\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= "submit=Compare&user1=".rawurlencode($finalrsname);
fwrite($fp, $out);
$page = "";
$page .= stream_get_contents($fp);
fclose($fp);
}
$page = explode('<tr><td align="right"><b>Skill</b></td><td> </td><td align="right"><b>Rank</b></td><td align="right"><b>Level</b></td><td align="right"><b>XP</b></td> </tr>',$page);
$page = explode('</body>',$page[1]);
$page = strip_tags($page[0]);
$page = str_replace(array(",","This webpage and its contents are copyright 1999 - 2006 Jagex Ltd. To use our service you must agree to our Terms+Conditions + Privacy policy"),"",$page);
$page = explode(" ",$page);
for($a = 0;$a <= 88; $a = $a + 4)
{
$hiscores[strtolower($page[$a])] = array("rank" => $page[$a+1], "level" => $page[$a+2], "xp" => $page[$a+3]);
}
return($hiscores[$skill][$item]);
}
?>
function hsc($finalrsname, $skill, $item)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$skill = strtolower($skill);
$fp = fsockopen("hiscore-web.runescape.com", 80, $errno, $errstr, 30);
if (!$fp) {
die("$errstr ($errno)<br />\n");
} else {
stream_set_timeout($fp,1);
$out = "POST /lang/en/aff/runescape/hiscorepersonal.ws HTTP/1.1\r\n";
$out .= "Host: hiscore-web.runescape.com\r\n";
$out .= "From: admin@runemasters.net\r\n";
$out .= "Content-length: ".(strlen(rawurlencode($finalrsname))+21)."\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: RuneSignatures/1.0\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= "submit=Compare&user1=".rawurlencode($finalrsname);
fwrite($fp, $out);
$page = "";
$page .= stream_get_contents($fp);
fclose($fp);
}
$page = explode('<tr><td align="right"><b>Skill</b></td><td> </td><td align="right"><b>Rank</b></td><td align="right"><b>Level</b></td><td align="right"><b>XP</b></td> </tr>',$page);
$page = explode('</body>',$page[1]);
$page = strip_tags($page[0]);
$page = str_replace(array(",","This webpage and its contents are copyright 1999 - 2006 Jagex Ltd. To use our service you must agree to our Terms+Conditions + Privacy policy"),"",$page);
$page = explode(" ",$page);
for($a = 0;$a <= 88; $a = $a + 4)
{
$hiscores[strtolower($page[$a])] = array("rank" => $page[$a+1], "level" => $page[$a+2], "xp" => $page[$a+3]);
}
return($hiscores[$skill][$item]);
}
?>
And this is an example of code I use for filling out fields:
CODE
// Load the GetXP script.
require("getxp.php");
// SKILL ONE: Hitpoints
$skill = Hitpoints;
$item = level;
$HP = hsc($finalrsname, $skill, $item);
if(empty($HP)) {
print "<tr><td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' /></td>
</tr>";
}
else
{
if($HP == Ranked) {
print "<tr><td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' /></td>
</tr>";
} else {
print "<tr>
<td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' READONLY value='$HP' /></td>
</tr>";
}
}
require("getxp.php");
// SKILL ONE: Hitpoints
$skill = Hitpoints;
$item = level;
$HP = hsc($finalrsname, $skill, $item);
if(empty($HP)) {
print "<tr><td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' /></td>
</tr>";
}
else
{
if($HP == Ranked) {
print "<tr><td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' /></td>
</tr>";
} else {
print "<tr>
<td width='50%'>HP: </td><td width='50%'><input name='hp' type='text' size='2' maxlength='2' READONLY value='$HP' /></td>
</tr>";
}
}
