simplexml_load_file 不起作用“php_network_getaddresses:失败:名称或服务未知”

发布于 2024-11-18 03:33:16 字数 2445 浏览 1 评论 0原文

我最近才开始收到这些警告,我不知道为什么,也不知道如何解决它。更让我困惑的是,它之前可以工作,我开始学习另一个课程,现在我开始收到这个错误......

我使用 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 17

Warning:
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 17

Warning: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2024-11-25 03:33:16

您遇到的是网络/DNS 问题,而不是 PHP 问题。看来您的机器无法解析api.flickr.com的IP。

“su”到您的网络服务器用户并尝试解析那里的名称,即

$ sudo bash
  # get root
$ su - apache
  # we're the apache user now
$ ping api.flickr.com

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.

$ sudo bash
  # get root
$ su - apache
  # we're the apache user now
$ ping api.flickr.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文