最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

feed - Fetch_Feed cURL error 28

programmeradmin1浏览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 = '.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?

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?

Share Improve this question edited Dec 31, 2020 at 7:23 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 30, 2020 at 4:40 Picard102Picard102 9331 gold badge10 silver badges23 bronze badges 2
  • Strange behaviour.. can you try to filter CURL settings like stackoverflow/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
Add a comment  | 

1 Answer 1

Reset to default 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 );
} );

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论