0

So whenever I try to use fetch_feed with urls like the one below, I get back "WP HTTP Error: cURL error 28: Operation timed out after 30070 milliseconds with 0 bytes received" However when I use just a plain cURL on the url get a response. So I can only conclude something in Fetch Feed is the issue. Anyone have a better idea how to get past this issue?

include_once( ABSPATH . WPINC . '/feed.php' );
$feed_url = 'https://www.cbc.ca/podcasting/includes/frontburner.xml';
$rss = fetch_feed( $feed_url );
var_dump($rss);

Edit: I did some digging in the fetch_feed function, and found it worked when I commented out

$feed->set_file_class( 'WP_SimplePie_File' );

Any reason that could be? Any way to make this change in the theme file so it's not changed when wordpress is updated?

2
  • Strange behaviour.. can you try to filter CURL settings like stackoverflow.com/a/54583058/591486 to see if they help resolve this?
    – Q Studio
    Commented Dec 30, 2020 at 9:02
  • I did try that and it didn't seem to help.
    – Picard102
    Commented Dec 30, 2020 at 16:03

1 Answer 1

2

Maybe it's just us, but it seems like you need to set a user agent other than the default which is stored in the SIMPLEPIE_USERAGENT constant, and with fetch_feed(), you can use the wp_feed_options hook to set a custom user agent — or none also worked for me.

Working example:

add_action( 'wp_feed_options', function ( $feed ) {
    $feed->set_useragent( 'MyPlugin/1.0' );              // works
    $feed->set_useragent( $_SERVER['HTTP_USER_AGENT'] ); // works
    $feed->set_useragent( '' );                          // empty; worked for me..

    // You can also try increasing the timeout, but the default one (10 seconds)
    // worked fine for me.
    $feed->set_timeout( 15 );
} );
3
  • Looks like this worked. Is that user agent set in $feed->set_file_class( 'WP_SimplePie_File' );? It also worked when I commented out that line.
    – Picard102
    Commented Dec 30, 2020 at 16:10
  • 1
    Yes, and you may also override the file class the same way WP did it. E.g. Clone the WP_SimplePie_File class then set the user agent directly in your class without using $feed->set_useragent().
    – Sally CJ
    Commented Dec 30, 2020 at 16:30
  • 1
    Amazing, thank you! This solved an issue that's been persistent for 2 years.
    – Picard102
    Commented Dec 30, 2020 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.