2014-01-27 07:26

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

  • curl
  • port
  • json
  • php

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.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享