protected function FetchItems($arrURLs, $numItems = 1) { // since 1.1.4 $strURLID = md5(serialize(is_string($arrURLs) ? array($arrURLs) : $arrURLs)); if (!isset($this->arrFeedItems[$strURLID])) { $this->arrFeedItems[$strURLID] = (array) get_transient('RCWUserAds_' . $strURLID); unset($this->arrFeedItems[$strURLID][0]); // casting array causes the 0 key, } // If it's out of stock, fill the array by fetching the feed. if (count($this->arrFeedItems[$strURLID]) < $numItems) { $oReplace = new ResponsiveColumnWidgets_HTMLElementReplacer($this->strCharSet); // When an array of urls is passed to the Simple Pie's set_feed_url() method, the memory usage increases largely. // So fetch the feeds one by one per url and store the output into an array. foreach ($arrURLs as $strURL) { $oFeed = $this->GetFeedObj($strURL, $numItems * 20); // multiplied by X to store items more than enough for next calls. foreach ($oFeed->get_items() as $item) { // foreach ( $oFeed->get_items( 0, $numItems * 3 ) as $item ) does not change the memory usage $this->arrFeedItems[$strURLID][] = $oReplace->Perform($item->get_content()); } // For PHP below 5.3 to release the memory. $oFeed->__destruct(); // Do what PHP should be doing on it's own. unset($oFeed); } unset($oReplace); // This life span should be little longer than the feed cache life span, which is 1700. set_transient('RCWUserAds_' . $strURLID, $this->arrFeedItems[$strURLID], 1800); // 30 minutes } $strOut = ''; shuffle($this->arrFeedItems[$strURLID]); for ($i = 1; $i <= $numItems; $i++) { $strOut .= array_pop($this->arrFeedItems[$strURLID]); } return $strOut; }