I am searching for profile numbers based off a list of members in my database, from a different site to insert into my database.

All goes well except searching for certain names causes a system failure on the other site making my script fail from that point on. It's not a random system error, always happens on the same people, but there are over 600 to go through nightly.

Is there any way I can get around their error by just skipping and going to the next? Or another way to improve the code?

magelo.php

<?
require_once('flagsdb.inc');
require_once('magelo.inc');
$flagsdb = FlagsDBConnect();

$selectSQL = "SELECT CharacterID, Name FROM `Character` WHERE MageloNumber = 0 AND Active = 1 ORDER BY Name";
$result = mysql_query($selectSQL, $flagsdb->link_id);

while( $row = mysql_fetch_object($result) )
{
	$characterName = $row->Name;
	$characterID = $row->CharacterID;
	echo "Looking up Magelo number for $characterName.<br/>\n";
	$mageloNum = findMageloNumber($characterName, "Quellious");
	if( $mageloNum != null )
	{
		$updateSql = "UPDATE `Character` SET MageloNumber=$mageloNum WHERE CharacterID = '$characterID'";
		$updateResult = mysql_query($updateSql, $flagsdb->link_id);

	echo "$characterName => $mageloNum<br/>\n";
}	
}

?>

magelo.inc

<?
require_once('httpfunctions.inc');

function findMageloNumber($characterName, $serverName)
{
	$pageContent = getWebPage("http://eq.magelo.com/quick_search.jspa?keyword=".$characterName);
	$playerAreaStart = strpos($pageContent, ">Race<");
	$playerAreaEnd = strpos($pageContent, "<!-- window (end)-->", $playerAreaStart);
	$pageContent = substr($pageContent, $playerAreaStart, $playerAreaEnd - $playerAreaStart);
	$pageContent = strtolower($pageContent);
	$characterName = strtolower($characterName);
	$serverName = strtolower($serverName);
	$offset = 0;
	while(true)
	{
		//echo "In loop, offset = $offset<br/>\n";
		$pos = strpos($pageContent, ">".$characterName."&nbsp;", $offset);
		if($pos === false )
		{
			//echo "pos is false<br/>\n";
			return null;
		}

	$serverNamePos = strpos($pageContent, ">".$serverName."<",$pos);
	if( $serverNamePos === false )
	{
		//echo "serverNamePos is false<br/>\n";
		return null;
	}

	$closingTrPos = strpos($pageContent, "</tr>",$pos);
	if( $closingTrPos === false )
	{
		//echo "closingTrPos is false<br/>\n";
		return null;
	}

	if( $closingTrPos > $serverNamePos )
	{
		//this is our guy!
		$previousContent = substr($pageContent, 0, $pos);
		$startingParenPos = strrpos($previousContent, "(");
		$closingParenPos = strrpos($previousContent, ")");

		$mageloNumber = substr($previousContent, $startingParenPos + 1, $closingParenPos - $startingParenPos - 1);
		return $mageloNumber;
	}
	//echo "Bad Match: $pos, $serverNamePos, $closingTrPos<br>\n";

	$offset = $pos + 1;

}

}
?>

httpfunctions.inc

<?
function getWebPage($toGet)
{
	$handle = fopen($toGet, "r");
	$sCache = '';
	while( !feof($handle) )
	{
		$sCache = $sCache.fread($handle, 1024);
	}
	fclose($handle);

return $sCache;
}
?>

This is the error I get when search fails which spams until explorer crashes

Looking up Magelo number for Losi.

Warning: fopen( http://eq.magelo.com/quick_search.jspa?keyword=Losi): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /home/content/k/o/t/kotnadmin/html/webcron/flagadmin/httpfunctions.inc on line 4

Warning: feof(): supplied argument is not a valid stream resource in /home/content/k/o/t/kotnadmin/html/webcron/flagadmin/httpfunctions.inc on line 6

Warning: fread(): supplied argument is not a valid stream resource in /home/content/k/o/t/kotnadmin/html/webcron/flagadmin/httpfunctions.inc on line 8

    Maybe you need to contact the site owner and tell them that their page is broken, because this doesn't have anything to do with your server.

    Headers returned by the server when I visited that address were:

    HTTP/1.1 500 Expression_creatureclasse_is_undefined_on_line_172_column_90_in_eqquick_searchftl

      Contact the owner of the other site you're trying to integrate with.

      Explain what you're trying to do, show them the logs and refer to the integration documentation you no doubt share which explains the protocol you're trying to use.

      Does the error happen when you do the same thing against their development / test server?

      Mark

        Write a Reply...