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
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?
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.
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.
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
.
If you are sure it is not a DNS issue, try restarting Apache. This solved it for me after 20 minutes of head scratching.