[PHP] SteamCondenserException: XML could not be parsed: String could not be parsed as XML

166 views
Skip to first unread message

Elliot Hesp

unread,
Feb 13, 2014, 10:38:47 AM2/13/14
to steam-c...@googlegroups.com
Hello,

I've had this working before now, but for some reason I'm getting this error.

Steam Condenser is auto loaded, all working etc.

I'm allowing the user to login with the Steam API, and getting the users community ID back. From here, I then use this with Steam Condenser:

<?php namespace Acme\Steam;

class SteamValidation
{
private $steam64Id;
public function __construct( $steam64Id ) {
$this->steamData = new \SteamId( (string)$steam64Id );
$this->steam64Id = $steam64Id;
}
...

Now in another class, I call this, as follows:

<?php

use Ssms\Steam\SteamValidation;

class SteamController extends BaseController {

        // 1) Get $steam64Id
        // var_dump( $steam64Id ) = string(17) "76561197960435530" (Robin Walker)

        $v = new SteamValidation( $steam64Id );
...

As I do that, I get the error:

SteamCondenserException
XML could
not be parsed: String could not be parsed as XML
/home/user/public_html/acme/vendor/koraktor/steam-condenser/lib/steam/community/XMLData.php (Line 38)

Any idea what's going on? Whether I do the below doesn't effect much it seems:

new \SteamId( (string)$steam64Id );
or
new \SteamId( $steam64Id );


Cheers
Elliot

Sebastian Staudt

unread,
Feb 13, 2014, 3:20:03 PM2/13/14
to steam-c...@googlegroups.com
Using the ID you supplied in your example code ("76561197960435530") this works perfectly using the current version of Steam Condenser.
What version are you using?
Or are you experiencing that problem with another ID?

Best regards,
Sebastian

Elliot Hesp

unread,
Feb 13, 2014, 3:34:37 PM2/13/14
to steam-c...@googlegroups.com
Version 1.3.7

Thing is it seems to work now, so all of the logic is correct. I basically grab the Steam 64 ID (http://forums.steampowered.com/forums/showthread.php?t=1430511) and then pass it through (as a string) into the SteamId class.

However sometimes it fails to work and throws the above error. Do you think this could be down to too many requests? Something up with Steam so doesn't return the correct XML back? Could do with some way of checking :/

Elliot Hesp

unread,
Feb 14, 2014, 6:26:06 AM2/14/14
to steam-c...@googlegroups.com
Hi Sebastian,

I did some digging.

In the XMLData.php file, I added a "die(var_dump($url));" just after the getData function, when the error occurred again.

The result of $url is (my profile): string(58) "http://steamcommunity.com/profiles/76561197993035972?xml=1". Now at the moment, it is giving me the following page on a 503:


Sorry
The Steam Community is currently unavailable. Please try again later.

Error 503 Service Unavailable

XID
: 2488044640

Now obviously this isn't XML, so I guess the SimpleXMLElement is throwing the error as it isn't XML. However when this does work, it will be XML and thus it works for me.

So I guess my questions would be:

  1. Do you know why (from your experience) I get a 503 - Assume something is up with Steam, but you never know.
  2. What would be an eloquent way to handle this? So I can display a message along the lines of "The Steam Community API is currently unavailable".  I would write something myself to help, but I don't really see this being up to the "code standard" for this.

Sebastian Staudt

unread,
Feb 14, 2014, 11:43:29 AM2/14/14
to steam-condenser
Was this StackOverflow question asked by you? http://stackoverflow.com/questions/21783722/simplexmlelement-http-status-code

This is exactly what I was assumed, so changing the relevant section in Steam Condenser seems to be the right choice here.
The root cause is Steam's unreliable XML API, though.


--
You received this message because you are subscribed to the Google Groups "Steam Condenser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to steam-condens...@googlegroups.com.
To post to this group, send email to steam-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/steam-condenser/23392fd7-bf94-4940-9152-fbf88d210113%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Elliot Hesp

unread,
Feb 14, 2014, 11:48:36 AM2/14/14
to steam-c...@googlegroups.com
Yeah it was, was trying to figure out how I could get around it without pestering you!

Do you think "file_get_contents" will be the best solution here? Not because of speed, but because curl might not be installed on everyone's system, it could cause some issues.

So basically the steps involved are:

1) Make the request with the URL.
2) Check the HTTP response code.
3) If it's a 200 or 301/302 then it's okay, if it's 50* then respond with an error.

Are you going to take a stab at that yourself? I can try writing something here but I know you'd be able to do it "properly".

Cheers :)
Message has been deleted

Elliot Hesp

unread,
Feb 14, 2014, 1:34:06 PM2/14/14
to steam-c...@googlegroups.com
Well I added the following code, and it seems to work - well, at least shows an error that relates to what's going on:

 protected function getData($url) {
if( ! $xml = @file_get_contents($url) ) {
$errorMessage = "An error occurred when retrieving XML from the Steam server . HTTP Response: " .  $http_response_header[0];
throw new SteamCondenserException($errorMessage, 0);
}
        try {
            return @new SimpleXMLElement($xml);
        } catch (Exception $e) {
            $errorMessage = "XML could not be parsed: " . $e->getMessage();
            if ((float) phpversion() < 5.3) {
                throw new SteamCondenserException($errorMessage, 0);
            } else {
                throw new SteamCondenserException($errorMessage, 0, $e);
            }
        }
    }

I saw your post on the WebApi part (stackoverflow), not sure how to use that at the moment but can look into it.  I'll plonk a pull request tomorrow or something, but feel free to show me the correct way of doing it using the WebApi.

Thanks!

Elliot

Sebastian Staudt

unread,
Feb 21, 2014, 4:28:55 PM2/21/14
to steam-c...@googlegroups.com
Did you already start working on a PR or are you still interested in doing one? Otherwise I'll implement this myself this weekend.
--
You received this message because you are subscribed to the Google Groups "Steam Condenser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to steam-condens...@googlegroups.com.
To post to this group, send email to steam-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/steam-condenser/c6cd60b9-424b-4648-ac11-bb961b9ccfb3%40googlegroups.com.

Elliot Hesp

unread,
Feb 21, 2014, 4:31:15 PM2/21/14
to steam-c...@googlegroups.com
Well I moved over to the WebApi in the end as it's more consistent. I can try a pull request, but stupid question: which branch?

On Friday, 21 February 2014 21:28:55 UTC, Sebastian Staudt wrote:
Did you already start working on a PR or are you still interested in doing one? Otherwise I'll implement this myself this weekend.

Am Freitag, 14. Februar 2014 schrieb Elliot Hesp :
Well I added the following code, and it seems to work - well, at least shows an error that relates to what's going on:

 protected function getData($url) {
if( ! $xml = @file_get_contents($url) ) {
$errorMessage = "An error occurred when retrieving XML from the Steam server . HTTP Response: " .  $http_response_header[0];
throw new SteamCondenserException($errorMessage, 0);
}
        try {
            return @new SimpleXMLElement($xml);
        } catch (Exception $e) {
            $errorMessage = "XML could not be parsed: " . $e->getMessage();
            if ((float) phpversion() < 5.3) {
                throw new SteamCondenserException($errorMessage, 0);
            } else {
                throw new SteamCondenserException($errorMessage, 0, $e);
            }
        }
    }

I saw your post on the WebApi part (stackoverflow), not sure how to use that at the moment but can look into it.  I'll plonk a pull request tomorrow or something, but feel free to show me the correct way of doing it using the WebApi.

Thanks!

Elliot

--
You received this message because you are subscribed to the Google Groups "Steam Condenser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to steam-condenser+unsubscribe@googlegroups.com.
To post to this group, send email to steam-condenser@googlegroups.com.

Sebastian Staudt

unread,
Feb 21, 2014, 4:50:55 PM2/21/14
to steam-c...@googlegroups.com
Well, if you're going to improve the current implementation of XMLData use 1.3-stable as your starting point.

But you may also want to help getting SteamId ready for Web API. That would be merged into master.
To unsubscribe from this group and stop receiving emails from it, send an email to steam-condens...@googlegroups.com.
To post to this group, send email to steam-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/steam-condenser/3baf438f-2d39-4ecf-905c-87e343efda6c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages