我刚刚开始收到这些警告,我不知道为什么,也不知道如何修复它。让我感到困惑的是,它之前正在工作,我开始在另一个班级工作,现在我开始收到这个错误......
即时通讯使用linux fedora&网络服务器的apache。
警告:simplexml_load_file() [function.simplexml负荷文件]: php_network_getaddresses:getaddrinfo 失败:未知的名称或服务 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-load-file]:失败 打开流: php_network_getaddresses:getaddrinfo 失败:未知的名称或服务 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;
}
}
?>
答案 0 :(得分:4)
您遇到网络/ DNS问题,而不是PHP问题。似乎您的机器无法解析api.flickr.com
的IP。
“su”到您的Web服务器用户并尝试解析那里的名称,即
$ sudo bash
# get root
$ su - apache
# we're the apache user now
$ ping api.flickr.com