PHP: Warning: file_get_contents

时间:2018-03-25 19:48:52

标签: php file-get-contents

I am no coder at all. Started learning html and php and bumped into a problem. There a few similar questions, but with my skill, I am not able to implement solutions.

$url = "https://www.bitstamp.net/api/ticker/";
$fgc = file_get_contents($url);
$json = json_decode($fgc, true);

$price = $json["last"];
$high = $json["high"];
$low = $json["low"];
$date = date("m-d-Y - h:i:sa");
$open = $json["open"];

After launching XAMPP on my machine and uploading php file, I get returned:

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /opt/lampp/htdocs/crypto_ticker/api.php on line 5

Warning: file_get_contents(https://www.bitstamp.net/api/ticker/): failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /opt/lampp/htdocs/crypto_ticker/api.php on line 5

Would someone please let me know what does that mean? Inability to connect to the page? The page loads itself perfectly fine, so must be something missing on my side. And what do I do then? Thank you in advance

2 个答案:

答案 0 :(得分:1)

Based on the error (Temporary failure in name resolution), it appears to be an issue with the PHP server accessing the website (bitstamp.net). While your web browser might be able to access it, the PHP service on the XAMPP server may not be able to communicate properly with it.

Try running nslookup www.bitstamp.net to ensure that a response is, in fact, provided. If it does resolve, try ensuring your connection is not incorrectly passing through a proxy and ensure your DNS settings are correct.

Based on other responses (https://stackoverflow.com/a/6361464/9549215), ensuring your ServerName directive in your Apache2 Virtual Host is correctly set MAY solve the issue; I have not tested this.

Best of luck with your problem!

答案 1 :(得分:0)

You can see the exact error in your output.

Temporary failure in name resolution

so you can't resolve the hostname "www.bitstamp.net". So you should check if you server has the correct DNS settings and can resolve the domain. You can use nslookup or dig to check it.