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

Timeout and failed to open stream warnings

Discussion in 'Census: General Discussion' started by Biotyk, Jun 13, 2014.

  1. Biotyk

    Biotyk Guest

    Hello all,

    I'm trying to make a simple page using the API and JSON (via file_put_contents).
    Sometimes it works and after I try a new query, e.g. use c:lang, my requests stop working.
    I'm running WAMP as a webserver on my PC.
    I thought my service ID is banned for few hours when I make improper query (since there is no documentation with all possible queries all I can do is try).
    But when I try to run the same query in the browser it works.
    What could be the reason?

    Regards
     
  2. Ryekir

    Ryekir Guest

    I'm a little confused by this, because the title seems to suggest that you're attempting to use the streaming API, but the details in the post seem to indicate that you're not and just using the regular REST API.

    It sounds like you are using PHP, in which case using file_get_contents (rather than file_put_contents) is what you'll want to use to make queries to pull data from the API (though I would personally use the PHP cURL library myself). Also, trying to use either of these methods to connect to the streaming API isn't going to work since that uses websockets. If you need to consume the stream on the server side, there are probably PHP libraries for using websockets.

    When your queries stop working, it's possible that the URL being sent by PHP to the API may be different than what you're using in your browser. Also, browsers will often be "intelligent" about the URLs and modify them appropriately when then detect certain things that could cause issues, so it would be best to post the specific queries you are trying to make that aren't working.
     
  3. Biotyk

    Biotyk Guest

    Yes, I am just using the REST API, these were the messages returned by the Apache.
    I was using file_get_contents and then json_decode to get data.
    Now I use PestJSON library to utilize cURL in a simpler matter:
    Code:
    <span style="color: #0000BB">$pest <span style="color: #007700">= new <span style="color: #0000BB">PestJSON <span style="color: #007700">(<span style="color: #DD0000">'http://census.daybreakgames.com/s:my_id/get/ps2:v2'<span style="color: #007700">);
    try {
    <span style="color: #0000BB">$api_world <span style="color: #007700">= <span style="color: #0000BB">$pest<span style="color: #007700">-><span style="color: #0000BB">get<span style="color: #007700">(<span style="color: #DD0000">'/world/?world_id=' <span style="color: #007700">. <span style="color: #0000BB">$world_id<span style="color: #007700">. <span style="color: #DD0000">'&c:show=name,state'<span style="color: #007700">);
    } catch (<span style="color: #0000BB">Pest_Exception $e<span style="color: #007700">)  {
    echo <span style="color: #DD0000">'ERR: ' <span style="color: #007700">. <span style="color: #0000BB">$e<span style="color: #007700">-><span style="color: #0000BB">getMessage<span style="color: #007700">();
    }
    And the response is:
    ERR: Failed to connect to census.daybreakgames.com port 80: Timed out

    But the same query puted in the browser on the same machine works perfectly.
    That is strange behavior.
     
  4. Ryekir

    Ryekir Guest

    That error message looks like it's probably not an issue with your code or the API itself, but between your server and the census API server. Are you able to make any successful queries? Have you tried manually using curl from the command line?

    When I first started, I had to have my hosting provider move me to a different server several times because it physically couldn't make a connection to census.daybreakgames.com (for some unknown reason), so you may be facing a similar problem.
     

Share This Page