UPDATED: Using the LOTRO Server feed

Some people had a bit of a hard time getting my server status feed to work properly. So, I’ll add a simple PHP example here.

If you open the feed, you will see it is divided in two main areas: FeedInfo and StatusList. The StatusList block is what we are using, so let’s take a good look at it. Every server is listed within it’s own <Server> block. In this block, you will see two elements, ServerName and ServerStatus. The first requires no explanation I think, the second is a simple boolean value; 1 for online, 0 for offline/unknown.

Now let’s start building some code for it. Remember, this is a quick and dirty version. Improvements can be made on the code, feel free to suggest them in the comments.

<?php
// Let's get the feed
$feed = @file_get_contents('http://muer.nl/lotro/serverstatus2.xml');
if (strlen($feed) == 0) {
echo "Loading feed failed.";
} else {
$serverXML = simplexml_load_string($feed);
foreach ($serverXML->StatusList->Server as $server) {
echo $server->ServerName . ' is ';
echo ($server->ServerStatus == 1 ? 'online':'offline');
echo '<br />';
}
}
?>

Now I’ll leave it to you how you work this into a website. This is the basics. Please do let me know how it turned out.

Update: I’ve added a second version of the XML, it will save you some time parsing it when you want to use a custom display. See http://muer.nl/lotro/serverstatus2.xml for the v2.

11 thoughts on “UPDATED: Using the LOTRO Server feed

  1. Hello. I just ajusted the code a bit and used in my site. The only problem that i have is that my ISP does not allow “fopen” so i cant “read” the xml file from your site. Is it possible to mail me the code for the xml, so i can place the xml machine in my site?

    Thanks

  2. Revealing my secret code? Nah :p What you can do, is use cURL to get the xml file.

    A sample:

    CODE:
    1. <?php
    2. $ch = curl_init();
    3. curl_setopt($ch, CURLOPT_URL, 'http://muer.nl/lotro/serverstatus2.xml');
    4. curl_setopt($ch, CURLOPT_HEADER, 0);
    5. $feed = curl_exec($ch);
    6.  
    7. if (curl_errno($ch))
    8.   echo "Loading server status failed";
    9. else
    10. {
    11.   $serverXML = simplexml_load_string($feed);
    12.   foreach ($serverXML->StatusList->Server as $server) {
    13.     echo $server->ServerName . ' is ';
    14.     echo ($server->ServerStatus == 1 ? 'online':'offline');
    15.     echo '<br />';
    16.   }
    17. }

  3. Hmm. You're printing out the entire XML file. Could you change the extention of that file to phps? That way I can see the actual source. Alternatively, send it to me via email: bas@this domain

  4. CODE:
    1. <?php
    2. $ch = curl_init();
    3. curl_setopt($ch, CURLOPT_URL, 'http://muer.nl/lotro/serverstatus2.xml');
    4. curl_setopt($ch, CURLOPT_HEADER, 0);
    5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    6. $feed = curl_exec($ch);
    7. curl_close($ch);
    8.  
    9. if (curl_errno($ch))
    10.   echo "Loading server status failed";
    11. else
    12. {
    13.   $serverXML = simplexml_load_string($feed);
    14.   foreach ($serverXML->StatusList->Server as $server)
    15.   {
    16.     echo $server->ServerName . ' is ';
    17.     echo ($server->ServerStatus == 1 ? 'online':'offline');
    18.     echo '<br />';
    19.   }
    20. }
    21. ?>

  5. You need to get your host to update PHP. They're running PHP4, which has been terminated last year. It's an unsafe PHP version. Tell your host to update to PHP5 and everything will work :)

Leave a Reply