From Drupal Simplefeed module: function simplefeed_item_feed_parse($process_feed, $cache_path) { // simplepie processing, fetch feeds include_once './'. drupal_get_path('module', 'simplefeed') .'/simplepie.inc'; $feed = new SimplePie(); /* You tell SimplePie what feed you want to get and where to cache it at. SimplePie looks to see if the feed is already cached: If the cache is fresh use that. If there is no cached copy at all, SimplePie will grab and cache the feed. If the cache is there but it's old (SimplePie defaults to 60 minutes; configurable with set_cache_duration()), then SimplePie will ask the feed if it has changed since the last time we grabbed it (this is the HTTPCG part). If it hasn't changed, we reset the timer on the cache's freshness and keep it for another 60 minutes before checking again. If the cache has changed, SimplePie dumps the existing cache (since the cache is just a copy of the feed), and grabs a new copy of the feed and uses it. This cache uses a combination of LAST-MODIFIED and ETAG headers, and other intelligent methods to only grab changed feeds. */ $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . base_path() . $cache_path); $feed->set_cache_duration(60); //new addition by me to try to fix the problem $feed->set_feed_url($process_feed->url); $feed->set_timeout(15); // prevent SimplePie from using all of it's data santization since we use Drupal's input formats to handle this $feed->set_stupidly_fast(TRUE); $success = $feed->init(); if ($success && $feed->data) { // loop through all of the items in the feed, faster than foreach $max = $feed->get_item_quantity(); for ($i = 0; $i < $max; $i++) { $item = $feed->get_item($i); // unique SHA-1 hash for a feed item $iid = $item->get_id(true); // make sure we don't already have this feed item $duplicate = db_result(db_query("SELECT iid FROM {simplefeed_feed_item} WHERE iid = '%s'", $iid)); if ($duplicate == '') { // add in tags if a vocabulary is set if (variable_get('simplefeed_vocab', 0)) { // add in tags from parent feed $tags = $process_feed->tags; // add in any tags that are found in the feed item itself from the originating site if (variable_get('simplefeed_categories', 0)) { if (count($item->get_categories()) > 0) { foreach ($item->get_categories() as $category) { $tags .= ', '. $category->get_label(); } } } // add any tags (either inheriting from parent feed or from parsing the feed item) to the feed item node if ($tags != '') { $item->taxonomy['tags'][$process_feed->vocab] = decode_entities($tags); } } $link = $item->get_permalink(); // this is node created date format for Drupal //$date = $item->get_date('Y-m-d H:i:s O'); $date = date('Y-m-d H:i:s O', time()); $body = $item->get_content(); // this strips out any tags that may appear as in the title, and makes sure " -> " for display $title = strip_tags(decode_entities($item->get_title())); // some feeds don't provide titles so we construct one with the first 72 characters of the body if (!$title) { // remove any HTML or line breaks so these don't appear in the title $title = trim(str_replace(array("\n", "\r"), ' ', strip_tags($body))); $title = trim(substr($title, 0, 72)); $lastchar = substr($title, -1, 1); // check to see if the last character in the title is a non-alphanumeric character, except for ? or ! // if it is strip it off so you don't get strange looking titles if (preg_match('/[^0-9A-Za-z\!\?]/', $lastchar)) { $title = substr($title, 0, -1); } // ? and ! are ok to end a title with since they make sense if ($lastchar != '!' and $lastchar != '?') { $title .= '...'; } } // create a feed item node $node = array('type' => 'feed_item', 'iid' => $iid); $values['title'] = $title; if ($date) { // "created" is a node property, however we have to use "date" to set this with drupal_execute since it is the form element name $values['date'] = $date; } $values['name'] = db_result(db_query('SELECT u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE nid = %d', $process_feed->nid)); $values['format'] = variable_get('simplefeed_format', 1); // $item->get_description() for teaser? $values['body'] = $body; $values['expires'] = $process_feed->expires; $values['url'] = $link != '' ? $link : $feed->get_permalink(); $values['fid'] = $process_feed->nid; $values['taxonomy'] = $item->taxonomy; // create a new feed-item node, adding in all of the other node defaults drupal_execute('feed_item_node_form', $values, $node); } // we unset $item each time to prevent any pass by reference memory leaks that PHP encounters with objects in foreach loops unset($item); } } else if (isset($feed->error)) { watchdog('simplefeed', t('The feed %feed could not be processed due to the following error: %error', array('%feed' => $process_feed->title, '%error' => $feed->error)), WATCHDOG_ERROR, l('view', 'node/'. $process_feed->nid)); } }