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 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗