doufangxie0203 2014-01-27 07:26
浏览 44
已采纳

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.

Thanks.

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

<?php
$APIcall = 'http://ontoserver.csiro.au:8080/ontoserver/resources/resolve?id=392608003';

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

echo 'Fetch data:<br>';
var_dump($OntoResponse);
?>

But when I publish it I get the following error: "Warning: file_get_contents(http://ontoserver.csiro.au:8080/ontoserver/resources/resolve?id=392608003) [function.file-get-contents]: failed to open stream: Connection timed out"

I'm stumped.. Thanks again.

  • 写回答

1条回答 默认 最新

  • 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?