wppaste
WordPress

fetch_rss( string $url ): MagpieRSS|false

Since
1.5.0
Source
wp-includes/rss.php:412
Build Magpie object based on RSS from URL.

Compatibility

WordPress
since 1.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$urlstring
URL to retrieve feed.

Return value

MagpieRSS|false
MagpieRSS object on success, false on failure.

Performance profile

How much work a call to fetch_rss() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Reaches an outbound HTTP request via wp_safe_remote_request().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
6–96

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 156.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • httpoutbound HTTP requestwp_safe_remote_request()one call below fetch_rss()

Further down the call graph this can also reach hook. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 117 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost fetch_rss() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!isset($url)6init()
isset($url) && !is_success()18–61init(), _fetch_remote_file(), is_success()
isset($url) && is_success()21–50init(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE"34–39init(), _fetch_remote_file()
isset($url) && $cache && $cache_status == "HIT" && isset($rss)36–38init(), ->get()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE"38–43init(), ->check_cache(), _fetch_remote_file()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE"40–43init(), _fetch_remote_file(), debug()
isset($url) && $cache40–53init(), ->get(), _fetch_remote_file()
isset($url) && $cache && $cache_status == "HIT" && isset($rss)40–42init(), ->get(), debug()
isset($url) && !$cache && $cache_status == "HIT" && isset($rss)40–42init(), ->check_cache(), ->get()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE"42–45init(), debug(), _fetch_remote_file()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)44–46init(), _fetch_remote_file(), ->set()
105 further outcomes, up to 96 instructions
isset($url) && $cache && $cache_status == "HIT" && isset($rss)44init(), debug(), ->get()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE"44–47init(), ->check_cache(), _fetch_remote_file(), debug()
isset($url) && !$cache44–57init(), ->check_cache(), ->get(), _fetch_remote_file()
isset($url) && !$cache && $cache_status == "HIT" && isset($rss)44–46init(), ->check_cache(), ->get(), debug()
isset($url) && $cache46–57init(), ->get(), _fetch_remote_file(), debug()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE"46–60init(), ->get(), ->get(), _fetch_remote_file()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE"46–49init(), debug(), ->check_cache(), _fetch_remote_file()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)48–50init(), _fetch_remote_file(), debug(), ->set()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)48–50init(), ->check_cache(), _fetch_remote_file(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE"48–49init(), debug(), _fetch_remote_file(), debug()
isset($url) && $cache48–59init(), debug(), ->get(), _fetch_remote_file()
isset($url) && $cache && $cache_status == "HIT" && isset($rss)48init(), debug(), ->get(), debug()
isset($url) && $cache_status == "HIT" && isset($rss)48init(), debug(), ->check_cache(), ->get()
isset($url) && $cache && isset($resp)50–60init(), ->get(), _fetch_remote_file(), ->set()
isset($url) && !$cache50–61init(), ->check_cache(), ->get(), _fetch_remote_file(), debug()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE"50–64init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)52init(), debug(), _fetch_remote_file(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE"52–64init(), ->get(), ->get(), _fetch_remote_file(), debug()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()52–54init(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)52–54init(), ->check_cache(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE"52–53init(), debug(), ->check_cache(), _fetch_remote_file(), debug()
isset($url)52–63init(), debug(), ->check_cache(), ->get(), _fetch_remote_file()
isset($url) && $cache_status == "HIT" && isset($rss)52init(), debug(), ->check_cache(), ->get(), debug()
isset($url) && $cache && isset($resp) && is_success()54–64init(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && isset($resp)54–64init(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && !$cache && isset($resp)54–64init(), ->check_cache(), ->get(), _fetch_remote_file(), ->set()
isset($url) && $cache54–63init(), debug(), ->get(), _fetch_remote_file(), debug()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE"54–66init(), debug(), ->get(), ->get(), _fetch_remote_file()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()55–57init(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)56–67init(), ->get(), ->get(), _fetch_remote_file(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()56init(), debug(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)56init(), debug(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)56init(), debug(), ->check_cache(), _fetch_remote_file(), ->set()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE"56–68init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), debug()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()58–65init(), ->check_cache(), _fetch_remote_file(), is_success()
isset($url) && $cache && isset($resp)58–66init(), debug(), ->get(), _fetch_remote_file(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()58–60init(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && !$cache && isset($resp) && is_success()58–68init(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && !$cache && isset($resp)58–68init(), ->check_cache(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url)58–67init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), debug()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE"58–70init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()59–61init(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()60–65init(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache && isset($resp) && !is_success()60–75init(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()60–71init(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)60–71init(), ->get(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)60–71init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE"60–70init(), debug(), ->get(), ->get(), _fetch_remote_file(), debug()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()60init(), debug(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp)60init(), debug(), ->check_cache(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache && isset($resp) && is_success()61–71init(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()62–67init(), debug(), _fetch_remote_file(), is_success()
isset($url) && $cache && isset($resp) && is_success()62–70init(), debug(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && isset($resp)62–70init(), debug(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && isset($resp)62–70init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), ->set()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()62–64init(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()63init(), debug(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && !$cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()64–69init(), ->check_cache(), _fetch_remote_file(), is_success(), debug()
isset($url) && !$cache && isset($resp) && !is_success()64–79init(), ->check_cache(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)64–73init(), debug(), ->get(), ->get(), _fetch_remote_file(), ->set()
isset($url) && $cache && isset($resp) && is_success()64–74init(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()64–75init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)64–75init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE"64–74init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), debug()
isset($url) && !$cache && isset($resp) && is_success()65–75init(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && isset($resp) && !is_success()66–79init(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()66–82init(), ->get(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()66–71init(), debug(), ->check_cache(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()66init(), debug(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && isset($resp) && is_success()66–74init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && isset($resp)66–74init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()67–78init(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()67init(), debug(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()68–71init(), debug(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache && isset($resp) && !is_success()68–81init(), debug(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()68–77init(), debug(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)68–77init(), debug(), ->get(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)68–77init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), ->set()
isset($url) && !$cache && isset($resp) && is_success()68–78init(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache && isset($resp) && is_success()69–77init(), debug(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && !$cache && isset($resp) && !is_success()70–83init(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()70–86init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()70–81init(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && is_success()70init(), debug(), ->check_cache(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()71–82init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()72–86init(), ->get(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache_status != "HIT" && $cache_status != "STALE" && isset($resp) && !is_success()72–75init(), debug(), ->check_cache(), _fetch_remote_file(), is_success(), debug()
isset($url) && isset($resp) && !is_success()72–85init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && isset($resp) && is_success()72–80init(), debug(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()72–81init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp)72–81init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), debug(), ->set()
isset($url) && isset($resp) && is_success()73–81init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && isset($resp) && !is_success()74–85init(), debug(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()74–88init(), debug(), ->get(), ->get(), _fetch_remote_file(), is_success()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()74–85init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()75–84init(), debug(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && !$cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()76–90init(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && isset($resp) && is_success()76–84init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && isset($resp) && !is_success()78–89init(), debug(), ->check_cache(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()78–92init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()78–87init(), debug(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()79–88init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), ->set()
isset($url) && $cache && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()80–92init(), debug(), ->get(), ->get(), _fetch_remote_file(), is_success(), debug()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && is_success()82–91init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), _response_to_rss(), debug(), ->set()
isset($url) && $cache_status == "HIT" && $cache_status == "STALE" && isset($resp) && !is_success()84–96init(), debug(), ->check_cache(), ->get(), ->get(), _fetch_remote_file(), is_success(), debug()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1566–9623
8.51566–9623
8.41566–96234 fewer instructions than PHP 8.3
8.31606–10023
8.21606–10023
8.11606–10023
7.41606–10023

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 5

Used by · 2

  • get_rss()Display RSS items in HTML list items.
  • wp_rss()Display all RSS items in a HTML ordered list.

Source code

function fetch_rss ($url) {	// initialize constants	init(); 	if ( !isset($url) ) {		// error("fetch_rss called without a url");		return false;	} 	// if cache is disabled	if ( !MAGPIE_CACHE_ON ) {		// fetch file, and parse it		$resp = _fetch_remote_file( $url );		if ( is_success( $resp->status ) ) {			return _response_to_rss( $resp );		}		else {			// error("Failed to fetch $url and cache is off");			return false;		}	}	// else cache is ON	else {		// Flow		// 1. check cache		// 2. if there is a hit, make sure it's fresh		// 3. if cached obj fails freshness check, fetch remote		// 4. if remote fails, return stale object, or error 		$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); 		if (MAGPIE_DEBUG and $cache->ERROR) {			debug($cache->ERROR, E_USER_WARNING);		} 		$cache_status 	 = 0;		// response of check_cache		$request_headers = array(); // HTTP headers to send with fetch		$rss 			 = 0;		// parsed RSS object		$errormsg		 = 0;		// errors, if any 		if (!$cache->ERROR) {			// return cache HIT, MISS, or STALE			$cache_status = $cache->check_cache( $url );		} 		// if object cached, and cache is fresh, return cached obj		if ( $cache_status == 'HIT' ) {			$rss = $cache->get( $url );			if ( isset($rss) and $rss ) {				$rss->from_cache = 1;				if ( MAGPIE_DEBUG > 1) {				debug("MagpieRSS: Cache HIT", E_USER_NOTICE);			}				return $rss;			}		} 		// else attempt a conditional get 		// set up headers		if ( $cache_status == 'STALE' ) {			$rss = $cache->get( $url );			if ( isset($rss->etag) and $rss->last_modified ) {				$request_headers['If-None-Match'] = $rss->etag;				$request_headers['If-Last-Modified'] = $rss->last_modified;			}		} 		$resp = _fetch_remote_file( $url, $request_headers ); 		if (isset($resp) and $resp) {			if ($resp->status == '304' ) {				// we have the most current copy				if ( MAGPIE_DEBUG > 1) {					debug("Got 304 for $url");				}				// reset cache on 304 (at minutillo insistent prodding)				$cache->set($url, $rss);				return $rss;			}

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/rss.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.