Simexml_Load_FileNot Working";php_Network_getAddresses:FAILED:名称或服务未知";
我最近才开始收到这些警告,我不确定为什么,也不知道如何修复它。更让我困惑的是,它以前是有效的,我开始在另一个类上工作,现在我开始收到这个错误...
IM在Web服务器上使用Linux fedora&;apache。
警告:implexml_Load_file() [unction.implexml-加载-文件]: 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) [unction.implexml-Load-Files]:失败 要打开流,请执行以下操作: Php_Network_getAddresses:getaddrinfo 失败:中的名称或服务未知 GetImagesFlickr.php 第17行
警告:implexml_Load_file() [函数.implexml-加载-文件]: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;
}
}
?>
解决方案
您遇到的是网络/dns问题,而不是php问题。您的计算机似乎无法解析api.flickr.com
的IP。
"su"切换到您的Web服务器用户,并尝试解析其中的名称,即
$ sudo bash
# get root
$ su - apache
# we're the apache user now
$ ping api.flickr.com
相关文章