simplexml_load_file 不起作用“php_network_getaddresses:失败:名称或服务未知”
我最近才开始收到这些警告,我不知道为什么,也不知道如何解决它。更让我困惑的是,它之前可以工作,我开始学习另一个课程,现在我开始收到这个错误......
我使用 linux fedora & 。 apache 用于网络服务器。
警告:simplexml_load_file() [function.simplexml-加载文件]: php_network_getaddresses:获取地址信息 失败:名称或服务未知 GetImagesFlickr.php 第 17 行
警告: simplexml_load_file(http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc) [function.simplexml-加载文件]:失败 打开流: php_network_getaddresses:获取地址信息 失败:名称或服务未知 GetImagesFlickr.php 第 17 行
警告:simplexml_load_file() [function.simplexml-load-file]:I/O 警告:无法加载外部 实体 “http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc” 在 /var/www/html/yahoo/GetImagesFlickr.php 第 17 行
<?php
class GetImagesFlickr
{
const API_KEY = "***"; // Flickr api key
const MAX_RESULTS_RETURNED = 50; // Max results returned in search
private $url; // Flickr webservice url
public function __construct ()
{
$this->url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=".self::API_KEY."&media=photos&per_page=".self::MAX_RESULTS_RETURNED;
}
public function getImages ($search_term)
{
// Perform search and store xml data
$xml_data = simplexml_load_file("{$this->url}&text={$search_term}");
$search_results = array();
// Go through xml data and store to array
foreach ($xml_data->photos->photo as $current_photo)
{
$id = $current_photo['id'];
$title = $current_photo['title'];
$farm = $current_photo['farm'];
$secret = $current_photo['secret'];
$server = $current_photo['server'];
$url = "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg";
$complete_photo = array (
'id' => $id,
'title' => $title,
'farm' => $farm,
'secret' => $secret,
'server' => $server,
'url' => $url
);
$search_results[] = $complete_photo;
}
return $search_results;
}
}
?>
I started getting these warnings just recently, im not sure why, nor do i know how to fix it. What confuses me more, it was working before, i started working on another class and now i starting getting this error...
im using linux fedora & apache for the webserver.
Warning: simplexml_load_file()
[function.simplexml-load-file]:
php_network_getaddresses: getaddrinfo
failed: Name or service not known in
GetImagesFlickr.php
on line 17Warning:
simplexml_load_file(http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc)
[function.simplexml-load-file]: failed
to open stream:
php_network_getaddresses: getaddrinfo
failed: Name or service not known in
GetImagesFlickr.php
on line 17Warning: simplexml_load_file()
[function.simplexml-load-file]: I/O
warning : failed to load external
entity
"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc"
in
/var/www/html/yahoo/GetImagesFlickr.php
on line 17
<?php
class GetImagesFlickr
{
const API_KEY = "***"; // Flickr api key
const MAX_RESULTS_RETURNED = 50; // Max results returned in search
private $url; // Flickr webservice url
public function __construct ()
{
$this->url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=".self::API_KEY."&media=photos&per_page=".self::MAX_RESULTS_RETURNED;
}
public function getImages ($search_term)
{
// Perform search and store xml data
$xml_data = simplexml_load_file("{$this->url}&text={$search_term}");
$search_results = array();
// Go through xml data and store to array
foreach ($xml_data->photos->photo as $current_photo)
{
$id = $current_photo['id'];
$title = $current_photo['title'];
$farm = $current_photo['farm'];
$secret = $current_photo['secret'];
$server = $current_photo['server'];
$url = "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg";
$complete_photo = array (
'id' => $id,
'title' => $title,
'farm' => $farm,
'secret' => $secret,
'server' => $server,
'url' => $url
);
$search_results[] = $complete_photo;
}
return $search_results;
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的是网络/DNS 问题,而不是 PHP 问题。看来您的机器无法解析
api.flickr.com
的IP。“su”到您的网络服务器用户并尝试解析那里的名称,即
You have a network/DNS problem, not a PHP problem. Seems your machine cannot resolve the IP of
api.flickr.com
."su" to your web server user and try to resolve the name there, i.e.