Support » Fixing WordPress » How do I extend fetch_feed timeout?

  • I am trying to load an RSS feed from betfair

    But I keep getting an error when I use the WP Error object that it is timing out.

    I have a backup source to load similar data from but it is not as complete. Therefore I want to be able to extend the time the feed is allowed to load e.g even up to 30 seconds if possible as I can then cache it for future use.

    The exact code is

    $rss = fetch_feed('');
    if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
       RSSDebug("no error");
       // Figure out how many total items there are, but limit it to 20.
       $maxitems = $rss->get_item_quantity(20); 
       RSSDebug("get 20 items");
       // Build an array of all the items, starting with element 0 (first element).
       $rss_items = $rss->get_items(0, $maxitems);
       $count = 0;
       $max = 10;
       RSSDebug("couldnt load feed!");
       RSSDebug("Error is " . $rss->get_error_message());

    Where RSSDebug just outputs a string to the HTML

    The messages I get are:

    couldnt load feed!
    Error is WP HTTP Error: Operation timed out after 10000 milliseconds with 0 bytes received.

    10 seconds seems to be too slow at times so I need longer and I am having to rely on another source which is not so good.

    I thought there would have been some overloaded constructor method to use which I could pass in a timeout but I cannot find anything online.

    Any help would be appreciated as I am debating just using a file_get_contents/my own xml parsing code – Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter strictly-software


    As a quick fix I just went straight for the SimplePie code that the WordPress code is wrapping around.

    $feed = new SimplePie();
    $feed->set_timeout(30); // set to 30 seconds
    if (!$feed->error()):
    	RSSDebug("no error");
    	$rss_items = $feed->get_items(0, 20);
    	$count = 0;
    	$max = 10;
    	RSSDebug("rss items");
    	RSSDebug("couldnt load feed!");
    	RSSDebug("Error is " . $feed->error());

    So I get any error message and can extend the timeout to 30 seconds.

    I still use my backup feed but at least I can get my main results if possible.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I extend fetch_feed timeout?’ is closed to new replies.