0

I started messing around with the Steam API a bit ago, and I made a simple site showing profile information using the GetPlayerSummaries method. It's been working great, right until some of my friends started adding iOS emotes in their name, which causes the following:

Fatal error: Maximum execution time of 300 seconds exceeded in file on line 137

This is what's on that line in the file:

public function getPlayerSummary($steamid) {
    $contents = file_get_contents( "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".SteamAPI_APIKey."&steamids=".$steamid );
    $json = json_decode($contents, true);

    foreach($json['response']['players'] as $key => $value) {
        ...
    }
}

(This is in a function, $steamid is defined when calling the function)

This should return (JSON):

{
"response": {
    "players": [
        {
            "steamid": "_removed_",
            "communityvisibilitystate": 3,
            "profilestate": 1,
            "personaname": "_removed_ ",
            "lastlogoff": 1426734965,
            "profileurl": "http://steamcommunity.com/id/_removed_/",
            "avatar": "_removed_",
            "avatarmedium": "_removed_",
            "avatarfull": "_removed_",
            "personastate": 0,
            "realname": "_removed_",
            "primaryclanid": "_removed_",
            "timecreated": 1349251405,
            "personastateflags": 0,
            "loccountrycode": "DE"
        }
    ]

}

}

But the "" in the personaname messes it up, as it works for everyone else without it :/ This is a ghost emote, same happens with another friend using a monkey emote in his name.

Would anyone have any idea how I could resolve this?

Michael
  • 3
  • 5
  • Please post more of the code, I don't think that `file_get_contents` is causing this (PHP is not very good at reporting errors), my guess would be that `json_decode` can't parse strange characters, you could [replace not utf-8 chars in content](http://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string) and then `json_decode` string – Bogdan Kuštan Mar 19 '15 at 08:30
  • Added a bit more, though having nothing but the `file_get_contents` in the function still causes it :/ – Michael Mar 19 '15 at 08:48
  • What happens if you try to read file char by char? http://pastebin.com/Qr7RxvHW – Bogdan Kuštan Mar 19 '15 at 09:06
  • That works! Setting the charset to UTF-8, it turns the emote into a square (and into the actual emote on my phone) - Should I use this, and then `json_decode` or would that be a bad idea? – Michael Mar 19 '15 at 09:16
  • What about: http://pastebin.com/9FTEsjYY reading file char by char is not very good idea :) – Bogdan Kuštan Mar 19 '15 at 09:21
  • Works as well, same result :) EDIT: Something is acting up ... using `file_get_contents` also works when it's in a file on its own :/ Uhm – Michael Mar 19 '15 at 09:23
  • Dont put it into file, read form URL :) – Bogdan Kuštan Mar 19 '15 at 09:34
  • Have a look: http://pastebin.com/FtQetQ2E - Btw you think we can find somewhere else to chat? (I don't have enough repo to chat on here :P) EDIT: IM AN IDIOT, I HAD TO USE `PRINT_R` .... then it works fine, derp. But yet still not in my function – Michael Mar 19 '15 at 09:40
  • google hangout b.kustan@gmail.com – Bogdan Kuštan Mar 19 '15 at 09:49

2 Answers2

0

put following line at the top of php file,

ini_set("max_execution_time", 0);
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
0

Note:

If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().

http://php.net/manual/en/function.file-get-contents.php

Mike
  • 96
  • 5