Fetch_Feed cURL error 28

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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 );
} );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x