Title: fetch_feed() returns no rss data
Last modified: February 14, 2018

---

# fetch_feed() returns no rss data

 *  Resolved [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/)
 * I recently moved to a new server that has PHP 7.0. Everything seems to be working
   but I have a problem with the fetch_feed() function. It doesn’t return any data.
   I’m using the code below to test and have tested with a lot of feeds. Same result
   every time.
 * I’ve also tried using curl from the command line of the server, and this is working
   without any problem. So there seems to be a problem in wordpress.
 * I have tried WP_DEBUG and enabling error_reporting. But I get no errors.
 * What could be the problem?
 *     ```
       add_action('init', 'testfetchfeed');
   
       function testfetchfeed () {
       	if (isset($_REQUEST['testfetchfeed'])) {
   
       		$rss = fetch_feed('http://en.blog.wordpress.com/feed/');
   
       		if (is_wp_error($rss)) {
       			echo $rss->get_error_message();
       		} else {
       			print_r($rss);
       		}
       		exit;
       	}
       }
       ```
   
 *     ```
       SimplePie Object
       (
           [data] => Array
               (
               )
   
           [error] => 
           [sanitize] => WP_SimplePie_Sanitize_KSES Object
               (
                   [base] => 
                   [remove_div] => 1
                   [image_handler] => 
                   [strip_htmltags] => Array
                       (
                           [0] => base
                           [1] => blink
                           [2] => body
                           [3] => doctype
                           [4] => embed
                           [5] => font
                           [6] => form
                           [7] => frame
                           [8] => frameset
                           [9] => html
                           [10] => iframe
                           [11] => input
                           [12] => marquee
                           [13] => meta
                           [14] => noscript
                           [15] => object
                           [16] => param
                           [17] => script
                           [18] => style
                       )
   
                   [encode_instead_of_strip] => 
                   [strip_attributes] => Array
                       (
                           [0] => bgsound
                           [1] => class
                           [2] => expr
                           [3] => id
                           [4] => style
                           [5] => onclick
                           [6] => onerror
                           [7] => onfinish
                           [8] => onmouseover
                           [9] => onmouseout
                           [10] => onfocus
                           [11] => onblur
                           [12] => lowsrc
                           [13] => dynsrc
                       )
   
                   [strip_comments] => 
                   [output_encoding] => UTF-8
                   [enable_cache] => 1
                   [cache_location] => ./cache
                   [cache_name_function] => md5
                   [timeout] => 10
                   [useragent] => 
                   [force_fsockopen] => 
                   [replace_url_attributes] => Array
                       (
                           [a] => href
                           [area] => href
                           [blockquote] => cite
                           [del] => cite
                           [form] => action
                           [img] => Array
                               (
                                   [0] => longdesc
                                   [1] => src
                               )
   
                           [input] => src
                           [ins] => cite
                           [q] => cite
                       )
   
               )
   
           [useragent] => SimplePie/1.3.1 (Feed Parser; http://simplepie.org; Allow like Gecko) Build/20141218193430
           [feed_url] => http://en.blog.wordpress.com/feed/
           [file] => 
           [raw_data] => 
           [timeout] => 10
           [force_fsockopen] => 
           [force_feed] => 
           [cache] => 1
           [cache_duration] => 86400
           [autodiscovery_cache_duration] => 604800
           [cache_location] => ./cache
           [cache_name_function] => md5
           [order_by_date] => 1
           [input_encoding] => 
           [autodiscovery] => 31
           [registry] => SimplePie_Registry Object
               (
                   [default:protected] => Array
                       (
                           [Cache] => SimplePie_Cache
                           [Locator] => SimplePie_Locator
                           [Parser] => SimplePie_Parser
                           [File] => SimplePie_File
                           [Sanitize] => SimplePie_Sanitize
                           [Item] => SimplePie_Item
                           [Author] => SimplePie_Author
                           [Category] => SimplePie_Category
                           [Enclosure] => SimplePie_Enclosure
                           [Caption] => SimplePie_Caption
                           [Copyright] => SimplePie_Copyright
                           [Credit] => SimplePie_Credit
                           [Rating] => SimplePie_Rating
                           [Restriction] => SimplePie_Restriction
                           [Content_Type_Sniffer] => SimplePie_Content_Type_Sniffer
                           [Source] => SimplePie_Source
                           [Misc] => SimplePie_Misc
                           [XML_Declaration_Parser] => SimplePie_XML_Declaration_Parser
                           [Parse_Date] => SimplePie_Parse_Date
                       )
   
                   [classes:protected] => Array
                       (
                           [Sanitize] => WP_SimplePie_Sanitize_KSES
                           [Cache] => WP_Feed_Cache
                           [File] => WP_SimplePie_File
                       )
   
                   [legacy:protected] => Array
                       (
                           [0] => WP_SimplePie_Sanitize_KSES
                           [1] => WP_Feed_Cache
                           [2] => WP_SimplePie_File
                       )
   
               )
   
           [max_checked_feeds] => 10
           [all_discovered_feeds] => Array
               (
               )
   
           [image_handler] => 
           [multifeed_url] => Array
               (
               )
   
           [multifeed_objects] => Array
               (
               )
   
           [config_settings] => 
           [item_limit] => 0
           [strip_attributes] => Array
               (
                   [0] => bgsound
                   [1] => class
                   [2] => expr
                   [3] => id
                   [4] => style
                   [5] => onclick
                   [6] => onerror
                   [7] => onfinish
                   [8] => onmouseover
                   [9] => onmouseout
                   [10] => onfocus
                   [11] => onblur
                   [12] => lowsrc
                   [13] => dynsrc
               )
   
           [strip_htmltags] => Array
               (
                   [0] => base
                   [1] => blink
                   [2] => body
                   [3] => doctype
                   [4] => embed
                   [5] => font
                   [6] => form
                   [7] => frame
                   [8] => frameset
                   [9] => html
                   [10] => iframe
                   [11] => input
                   [12] => marquee
                   [13] => meta
                   [14] => noscript
                   [15] => object
                   [16] => param
                   [17] => script
                   [18] => style
               )
   
       )
       ```
   
    -  This topic was modified 8 years, 4 months ago by [niska](https://wordpress.org/support/users/niska/).
    -  This topic was modified 8 years, 4 months ago by [niska](https://wordpress.org/support/users/niska/).

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9974577)
 * I used your code on my site and it returns feeds without any trouble (PHP 7).
   Thus the problem is something with one of your plugins or your theme that apparently
   does not play well with PHP 7. Please install and activate the [health-check](https://wordpress.org/plugins/health-check/)
   plugin. Temporarily copy your code to the functions.php file of the twentyseventeen
   theme. If it does not exist on your installation, install it, as it’s needed 
   by health-check. From the dashboard part of the admin menu, open health check
   and go to the troubleshooting tab. Activate troubleshooting mode. You should 
   find your test code outputs feed data.
 * Start restoring your theme and plugins from the troubleshooting admin bar item.
   Restore one at a time, testing after each. When your test again fails, the last
   activated module has a problem with PHP 7.
 *  Thread Starter [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9974764)
 * Thanks for reply. I have installed and activated health-check plugin. I couldn’t
   find anything problematic about my install, except it recommends me to update
   to PHP 7.2 (I’m using PHP 7.0.27). See info below.
 * I used the health-check troubleshoot mode to disable all plugins and themes –
   except the code above. However, my test code still doesnt output feed data.
 * Not sure what to do now. I’m pretty sure it is not my server that has problems,
   since curl from the command line is working. Also, downloading and installing
   plugins from within wp-admin is working. So fetching external data is working.
   For some reason external data can not be fetched using the fetch_feed() function.
 * Any ideas on how to proceed?
 *     ```
       ### WordPress ###
   
       Version: 4.9.4
       Language: sv_SE
       Permalink structure: /%postname%/
       Is this site using HTTPS?: Yes
       Can anyone register on this site?: No
       Default comment status: closed
       Is this a multisite?: No
       User Count: 474
       Communication with WordPress.org: WordPress.org is reachable
       Create loopback requests: The loopback request to your site completed successfully.
   
       ### Drop-ins ###
   
       advanced-cache.php: Advanced caching plugin.
   
       ### Active theme ###
   
       Name: 
       Version: 1.0.0
       Author: Anonymous
       Author website: Undefined
       Parent theme: Twenty Sixteen
       Supported theme features: automatic-feed-links, title-tag, custom-logo, post-thumbnails, menus, html5, post-formats, editor-style, customize-selective-refresh-widgets, custom-background, custom-header, widgets
   
       ### Other themes (1) ###
   
       Twenty Sixteen (twentysixteen): Version 1.4 by the WordPress team
   
       ### Must Use Plugins (1) ###
   
       Health Check Disable Plugins: Version 1.1
   
       ### Media handling ###
   
       Active editor: WP_Image_Editor_GD
       Imagick Module Version: Imagick not available
       ImageMagick Version: Imagick not available
       GD Version: bundled (2.1.0 compatible)
       Ghostscript Version: Unable to determine if Ghostscript is installed
   
       ### Server ###
   
       Server architecture: Linux 3.16.0-4-amd64 x86_64
       PHP Version: 7.0.27-1~dotdeb+8.1 (Supports 64bit values)
       PHP SAPI: fpm-fcgi
       PHP max input variables: 1000
       PHP time limit: 300
       PHP memory limit: 256M
       Max input time: 60
       Upload max filesize: 2M
       PHP post max size: 8M
       cURL Version: 7.38.0 OpenSSL/1.0.1t
       SUHOSIN installed: No
       Is the Imagick library available: No
   
       ### Database ###
   
       Extension: mysqli
       Server version: 5.5.5-10.1.31-MariaDB-1~jessie
       Client version: mysqlnd 5.0.12-dev - 20150407 - $Id: b6c5906d452ec590732a93b051f3827e02749b83 $
       Database prefix: wp_
   
       ### WordPress constants ###
   
       ABSPATH: /www/wp/public_html/
       WP_HOME: Undefined
       WP_SITEURL: Undefined
       WP_DEBUG: Disabled
       WP_MAX_MEMORY_LIMIT: 256M
       WP_DEBUG_DISPLAY: Enabled
       WP_DEBUG_LOG: Disabled
       SCRIPT_DEBUG: Disabled
       WP_CACHE: Enabled
       CONCATENATE_SCRIPTS: Undefined
       COMPRESS_SCRIPTS: Undefined
       COMPRESS_CSS: Undefined
       WP_LOCAL_DEV: Undefined
   
       ### Filesystem permissions ###
   
       The main WordPress directory: Writable
       The wp-content directory: Writable
       The uploads directory: Writable
       The plugins directory: Writable
       The themes directory: Writable
       The Must Use Plugins directory: Writable
       ```
   
 *  Thread Starter [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9975081)
 * phpinfo says
 * allow_url_fopen = Off
    cURL support = enabled
 * Not sure if it matters or not.
 *  Thread Starter [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9976544)
 * This code is working:
 *     ```
       $c = curl_init();
       curl_setopt($c, CURLOPT_URL, 'https://en.blog.wordpress.com/feed/');
       curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
       $result = curl_exec($c);
       ```
   
 * I think fetch_feed() is using curl – so why is not fetch_feed() working for me?
 * Please advice.
 *  Thread Starter [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9979161)
 * I solved it. php-xml parser module was missing.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9979220)
 * fetch_feed() uses SimplePie_File, which in turn tries to use cURL if available.
   It falls back to file_get_contents() if cURL fails.
 * I take it the SimplePie object in your OP is what your code outputs? That’s quite
   strange to get an empty data element. As you can imagine, it usually contains
   an RSS feed data structure. Any errors that occur end up returning a WP_Error
   object, which results in a simple error message being output by WP such as ‘Unable
   to decode HTTP “gzip” stream’ or whatever. SimplePie returning an empty object
   is not “seen” as an error by WP. SimplePie is pretty good at catching error conditions
   and reporting them back, so getting an empty object without throwing an error
   is rather unusual.
 * Are you really trying to get the feed from blog.wordpress.com or is that a substitute
   for a site you’d rather not disclose? One thought was the site is returning an
   empty feed and SimplePie is correctly returning what it got from the site. Then
   the problem is that site and not your server. But of course the WP blog feed 
   works and the problem lies elsewhere if that is indeed the feed you are trying
   to get.
 * But then you report a direct cURL request gets a feed. I assume you are using
   whatever feed URL you really want, so that throws suspicion back to fetch_feed().
   fetch_feed() basically just instantiates SimplePie and tells it to get a feed.
   There’s not much to get wrong there. All the heavy lifting, such as it is, is
   done by SimplePie.
 * Since I cannot replicate the issue you are experiencing, it’s difficult to suggest
   a solution, other than do what I would do if I could replicate the problem. I
   would trace through the relevant code, returning or outputting debug data at 
   key points to verify all is so far working correctly. Eventually I’d come across
   the point where things go wrong and it’s usually clear at that point why it went
   wrong and what is needed to prevent it.
 * It can be very tedious tracing through source code, hoping to find where the 
   error occurs. It’s often more efficient to “divide and conquer”. Find a point
   in source roughly halfway through the process and check the status there. This
   tells you if the problem is before or after that point. Pick another point roughly
   halfway into the problem half and check again. Keep dividing like that until 
   you’ve drilled down to the exact place where the problem occurs. This is most
   effective if you understand the code on sight. If it’s not clear, stepping through
   procedurally will better help you understand what the code is doing, as tedious
   as that may be.
 * [fetch_feed() source](https://developer.wordpress.org/reference/functions/fetch_feed/#source)
   
   [SimplePie Source](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-simplepie.php)
   [SimplePie_File Source](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/SimplePie/File.php)
 *  Thread Starter [niska](https://wordpress.org/support/users/niska/)
 * (@niska)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9979386)
 * Thanks for your reply. I have marked this thread as solved since the solution
   was to install the php-xml parser module.
 * sudo apt-get install php-xml
 * SimplePie doesn’t throw an error in this scenario so that’s why it was hard to
   find the solution.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9982838)
 * Ah! Yes, XML support is rather important for handling feeds 🙂 Nice work tracking
   that down. I’m glad you were able to solve this.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘fetch_feed() returns no rss data’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/fetch_feed-returns-no-rss-data/#post-9982838)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
