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_contents()
to fetch JSON values from another script.
PHP Version is 5.2.4allow_url_fopen
is ON
Warning:
file_get_contents()
[function.file-get-contents]
:php_network_getaddresses
:getaddrinfo
failed: Name or service not known in/var/www/html/2009/functions/functions.products.php
online 5
Warning:
file_get_contents(http://data.example.com/new-data.php) [function.file-get-contents]
: failed to open stream:Success in /var/www/html/2009/functions/functions.products.php
online 5
The script is being ran from: http://www.example.com
The location passed into the function is http://data.example.com/new-data.php
Note: Same domain name, but two different servers.
function getData() {
$location = "http://data.mysite.com/new-data.php";
$contents = file_get_contents($location);
$jsonVars = json_decode($contents);
return $jsonVars
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With