PHP : file_get_contents($loc) fails

前端 未结 5 557
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 18:01

I just moved a project from localhost over to my remote server, and noticed that some of my scripts stopped working. Most importantly was one that relied upon file_get

相关标签:
5条回答
  • 2020-12-03 18:28

    Please include more information, does $contents contain anything? Remember to do json_decode($contents, true) if you want it as a php array otherwise its a stdClass that gets returned.

    Could it have a problem resolving the hostname? is data.mysite.com the same machine as mysite.com?

    0 讨论(0)
  • 2020-12-03 18:36

    Name or service not known

    DNS is broke. Can you ping data.mysite.com from a shell on the machine (assuming you have one)?

    Try replacing data.mysite.com with a fixed IP address for now.

    0 讨论(0)
  • 2020-12-03 18:37

    Look at your /etc/hosts on the remote server. If it's empty, you need to add '127.0.0.1 localhost' to it.

    Unless it's one of the varieties of VPS where the loopback interface hits the outer machine; on those, you need to use your VPS's IP number instead of 127.0.0.1.

    0 讨论(0)
  • 2020-12-03 18:40

    Also you can try curl:

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_URL, 'http://url.url');
    $result = curl_exec($curl);
    curl_close($curl);
    

    And you get what you want in $result.

    0 讨论(0)
  • 2020-12-03 18:40

    If you are sure it is not a DNS issue, try restarting Apache. This solved it for me after 20 minutes of head scratching.

    0 讨论(0)
提交回复
热议问题