2014-01-27 07:26 阅读 39

PHP API调用使用file_get_contents()在共享主机上超时

So I'm trying to query an API and get a JSON object back. All works well on my local WAMP install, but when I deploy it to the server, the API query fails :( I've tried using cURL and file_get_contents(). With the same outcome. I've tried two hosts, same problem.

I looked at this question which sounds exactly like my problem. But no luck. And this other question sounds more like my problem, the problem was to do with the hosts firewall. But no detail on how he fixed it (and I can't comment yet)?

The script executes fine(on server) if the URL is say, some wikipedia page. But not the API service I'm targeting.

The API uses port 8080, so I'm suspecting that's got something to do with it, now I'm after tips on how I might be able to adress this.


[Update:] My Webhost says the problem is with my (quote) "codes"... So here's my test script. (Which runs fine on localhost)

$APIcall = '';

echo 'Contacting: ' . $APIcall.'<br>';
$OntoResponse = file_get_contents($APIcall, true);

echo 'Fetch data:<br>';

But when I publish it I get the following error: "Warning: file_get_contents( [function.file-get-contents]: failed to open stream: Connection timed out"

I'm stumped.. Thanks again.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douan7601 douan7601 2014-07-01 03:58

    The script executed without problem on my local WAMP server. My solution was to host the script on a different host (Azure), and it worked fine first time. (no special setup)

    I never worked out the specific cause for this, but I'm fairly confident it's something in my shared web hosting configuration. I was trying to host my script using budget shared hosting service(Crazy Domains).

    Note: Other than this, I've been happy with my host provider. But help or configuring setup to do this seems to be beyond their offering.

    点赞 评论 复制链接分享