Why does the connection time out?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #1

    Why does the connection time out?

    I'm writing a quick little script to grab some information from Stickam.com, specifically using the "API" they have set up to get a user id from a provided username, and a username from a provided userid. These are both publically accessible pieces of information, so I'm not getting into anything I shouldn't, I'm just using the publically accessible API instead of scraping the HTML.

    For some reason I can't explain though, I can't seem to get the contents of the page using PHP. Here's my code:

    Code:
    $username = @$_GET['username'];
    if(!$username) {
      die("no username");
      }
    
    $url = "http://www.stickam.com/servlet/ajax/getLiveUser?uname=".$username;
    $html = file_get_contents($url, false, $context);
    
    echo "<pre>";
    echo $html;
    echo "</pre>";
    But everytime I load this page on my server, I get this response:

    Warning: file_get_conten ts(http://www.stickam.com/servlet/ajax/getLiveUser?una me=[username]) [function.file-get-contents]: failed to open stream: Connection timed out in [file] on line 7

    I can load it just fine on my Apache server running on my personal computer, and I can load it in my browser (both IE9 and Firefox), but not on my website. I've tried mimicking the headers that my browser sends and creating a stream context to send with the file_get_conten ts() call, but so far nothing seems to work.

    Any ideas?
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Have you tried hard coding a username?

    Not really sure why you would get a timeout but I attempted this with a hardcoded username I saw on the homepage and got "[]" as the return string. Tried several usernames with the same result.

    Also tried this using curl instead of file_get_conten ts and had the same result. You may also want to give curl a try.

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      I've tried both cURL and file_get_conten ts, neither work, and cURL is a pain (for me). you'll get a [] if the user is not currently online, otherwise you'll get an array of information about the user.

      I don't think hadcoding a user would hep, but I'll try. You can see from the error message that it is indeed resolving the proper URL, and like I said this works perfectly fine on the Apache server installed on my personal computer and run from localhost. I literally wrote the code on my local server, tested it, then uploaded it to my web server and it no longer worked.

      I'll try a hardcoded username though, see what I get, hold up...

      Nope, same result.

      All that happens is the page appears to load for about 10 seconds, then it comes up with that error message.

      Obviously something is weird here, I can't imagine that Stickam would ban requests from my server when there are other sites, ike 4hds.com, that poll it way more often and way more heavily.

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        What is in your $context variable?

        I am able to get both curl and file_get_conten ts to work both locally and on a test server.

        Comment

        • HaLo2FrEeEk
          Contributor
          • Feb 2007
          • 404

          #5
          Right now just a UserAgent string, my UserAgent string:

          Code:
          $opts = array('http' => array('header' => 'user_agent' => "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
          $context = stream_context_create($opts);
          And it still doesn't work from my web server, but works perfectly fine from my local server.

          I think Stickam blacklisted my server's IP.

          Comment

          Working...