1. I have corrected the e-mail settings so that outgoing e-mails from these forums should be sent now. If you tried to Register or Reset your Password, please try again!
    Dismiss Notice

Some PHP and a question about rapid multiple hits

Discussion in 'Census: General Discussion' started by Lempo, Feb 8, 2012.

  1. Lempo

    Lempo Guest

    Code below was from initial work, there is no error checking in it but it works

    Members that do not populate the member collection because they have not logged in will generate warnings of Node no longer exists, that is fixed in my active code now, feel free to use any or all of this just be warned of this. 

    This is on a smaller scale on my end, I am making custom reports for our guild and for some raiding guilds where I know the leaders/officers. I am caching the guild data also will be caching spells, AA's and items. For now I am simply caching them as an XML file i.e. ./data/spell/707859362.xml would be loaded if it had already been cached if not [url="census.daybreakgames.com/xml/get/eq2/spell/707859362">census.daybreakgames.com/xml/get/eq2/spell/707859362[/url] would be requested, eventually I may put it into a database but I want to have a firm idea of the final design I want first then just import the cached data.

    Obviously this will be requesting a lot of information initially but as it iterates through the members it will begin to find more and more cached data.

    Do I need to throttle these requests? In the first pass it may make 1000's of requests to spells and several hundred to items and very rapidly as it loops through.

    <?php$xml=getGuildData('YOUR GUILD HERE','GUILD WORLD HERE');displayGuildData($xml);exit;?>

    <?phpfunction getGuildData($guildName, $serverName){    $url = 'census.daybreakgames.com/xml/get/eq2/guild/?name='.$guildName.'&world='.$serverName.'&c:resolve=members(name,type,spell_list,alternateadvancements,equipmentslot_list,stats,resists,secondarytradeskills,tradeskills)';  $filename = './data/guilds/'.$guildName.'('.$serverName.')'.'.xml';  if (file_exists($filename))      {      $tdiff  =round((time()-filemtime($filename))/60);      echo 'Cached data found - '.$tdiff.' mins old';      if ($tdiff < 120)     // Data stale after 2 hours          {           $xml = simplexml_load_file($filename);            echo '
    Using cached guild data';         }         else         {           echo '
    '.$url.'
    Cached data was refreshed';           $xml = simplexml_load_file($url);         }     }     else     {      $xml = simplexml_load_file($url);       echo $url.'
    File not cached - New Data Retrieved
    ';      $xml->asXML($filename);                 }  return $xml;}

    function displayGuildData($xml){  $dGuildData  = $xml->guild->attributes();  echo '
    ';  echo '<table border="1">';  echo '<tr><td align="center" colspan="2">'.$dGuildData->name.' - '.$dGuildData->world.'</td></tr>';  echo '<tr><td> Founded - '.date("F d Y",(int)($dGuildData->dateformed)).'</td>';    echo '<td>'.$dGuildData->members.' members ('.$dGuildData->accounts.' unique)</td></tr>';  echo '<tr><td colspan="2"><table width="100%" border="1">';    echo '<tr align="center"><td>NAME</td><td>LEVEL</td><td>CLASS</td><td>RACE</td>';  $bgColor = 'CCCCDD';  for ($i = 0; $i < sizeof($xml->guild->member_list->member); $i++)      {        $bgColor=toggleBgColor($bgColor);        echo '<tr bgcolor="'.$bgColor.'">';       echo '<td>'.$xml->guild->member_list->member[$i]->name->attributes()->first.'</td>';        echo '<td>'.$xml->guild->member_list->member[$i]->type->attributes()->level.'</td>';              echo '<td>'.$xml->guild->member_list->member[$i]->type->attributes()->class.'</td>';        echo '<td>'.$xml->guild->member_list->member[$i]->type->attributes()->race.'</td>';       echo '</tr>';      }   echo '</table></td></tr>';  echo '</table>';}

    function toggleBgColor($bgColor){ if ($bgColor == 'CCCCDD')  {$bgColor = 'FFFFFF';}  else {$bgColor = 'CCCCDD';}  // Just a hint of blue return $bgColor;  }?>

     
  2. Lempo

    Lempo Guest

    Also spells, items, AA's will not be considered stale after 2 hours, probably 60 or 90 days before a request would be made to update them.

     
  3. DanKinney

    DanKinney Guest

    For now, don't worry about the throttle, and we'll keep an eye on it.

    We are soon going to be adding more metrics to requests.  If you are going to do this, I'd like you to use a serviceID so that we can make sure that we know what is going on.

    To use a serviceID, send an email to [url="mailto:[email protected]">[email protected][/url] and request an identifier.  Then, use this identifier in each of your queries as follows:

    census.daybreakgames.com/s:serviceID/yaml/get/eq2/

    (replacing serviceID with the one you have registered)

    I'll write up a more complete explanation of this (and its benefits) shortly.

    -dan

     
  4. Lempo

    Lempo Guest

    Thanks Dan, I just sent the request in, how long should it take to get back?

    I guess I'll hold off until I get it so the metrics on what I am doing can be recorded/analyzed.

     
  5. DanKinney

    DanKinney Guest

    You should be ready to go.  Don't worry about the metrics though...they are not that close.

    -dan

     
  6. Lempo

    Lempo Guest

    Thanks Dan,

    That was quick. I'll get it added and do some thrashing tonight after raid if I can.

     

Share This Page