file_get_contents not working -- sometimes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akristof
    New Member
    • Nov 2011
    • 25

    file_get_contents not working -- sometimes

    Okay, here's a puzzle worthy of Sherlock Holmes.

    There's an API I am working with in PHP by fetching the contents of a GET request using file_get_conten ts($url), where $url is the API request.

    Here are the facts of what is and isn't working for me.

    1. The main problem (and reason I am asking this question) is that I get a timeout on the file_get_conten ts
    2. However, when I run the API call in the browser, it's working fine and I get a valid response (ie, I know the API is up)
    3. When I use file_get_conten ts on any other site, I get a valid response.
    4. When I use file_get_conten ts to call the API from another server altogether, it works fine.

    Which leads me to believe that there is something about the interaction of the original server and the API provider that is causing a problem. But what? ALSO, this worked fine up until a week ago, making this even more confusing.

    Any other ideas?

    PS: I tried CURL and I get the same responses in all situations.
  • jdstankosky
    New Member
    • Sep 2012
    • 30

    #2
    Do you have a snippet of your code to show us?

    Did the API make ANY changes at all that might impact this, even if they didn't inform you?

    Were any changes made to your server around that time?

    Odd that this would be working fine, only to stop recently.

    Comment

    • akristof
      New Member
      • Nov 2011
      • 25

      #3
      Code:
      $link='http://xyz';
      $token='xyz';
      $request='http://www.xyz.com/api/article?token='.$token.'&url='.urlencode($link);
      $response = file_get_contents($request);
      Where XYZ is actual values obviously.
      I spoke with the API provider and they say no changes on their side.
      I haven't done anything to my server..not sure if the provider did something? But like I said, the same code works fine on another server I have with the same provider.

      Comment

      • jdstankosky
        New Member
        • Sep 2012
        • 30

        #4
        If the token isn't static, and it's generated by various unique factors, such as referrer information in the header data and hardware/software platforms in use, perhaps your provider made some change that would require you to see if the token you're using needs updated?

        Comment

        • akristof
          New Member
          • Nov 2011
          • 25

          #5
          Thanks...I know it's not the token...like I said, the API call works fine when I do it in the browser.

          Comment

          Working...