PHP:file_get_contents($ loc)失败 [英] PHP : file_get_contents($loc) fails
问题描述
我刚刚将一个项目从localhost移到了我的远程服务器上,并且注意到我的某些脚本停止工作了.最重要的是依靠file_get_contents()
从另一个脚本中获取JSON值的
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版本为5.2.4
allow_url_fopen
已打开
PHP Version is 5.2.4
allow_url_fopen
is ON
警告:
file_get_contents()
[function.file-get-contents]
:php_network_getaddresses
:getaddrinfo
失败:line 5
警告:file_get_contents(http://data.example.com/new-data.php) [function.file-get-contents]
:无法打开流:line 5
上的Success in /var/www/html/2009/functions/functions.products.php
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
on line 5
脚本从以下位置运行:http://www.example.com
传递给函数的位置是http://data.example.com/new-data.php
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
}
推荐答案
名称或服务未知
Name or service not known
DNS已损坏.您可以从计算机上的外壳(假设您有一个外壳)ping data.mysite.com
吗?
DNS is broke. Can you ping data.mysite.com
from a shell on the machine (assuming you have one)?
现在尝试用固定的IP地址替换data.mysite.com
.
Try replacing data.mysite.com
with a fixed IP address for now.
这篇关于PHP:file_get_contents($ loc)失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!