Here's the original code that doesn't seem to be caching real well.
PHP Code:
<?PHP
define('MAX_ITEMS', 100);
require_once('magpies/rss_fetch.inc');
$query = 'SELECT query;// Undefined here but defined in real code $result=mysql_query($query); $num=mysql_numrows($result);
$urls = Array();
for ($n = 0; $n < $num-1; $n++) {
$blogRSS=mysql_result($result,$n,"blogRSS"); $urls[]=$blogRSS; }
$items = array();
// loop thru all urls & merge feeds into master array foreach ( $urls as $url ) { $rss = fetch_rss($url); if (!$rss) continue; $items = array_merge($items, $rss->items); }
// sort all items in array by date usort($items, 'date_cmp');
if (count($items) > MAX_ITEMS) $items = array_slice($items,0,MAX_ITEMS); // generate ouput array $out = array();
foreach ($items as $item) {
$href = $item['link']; $title = $item['title']; $desc = strip_tags(summary($item['description'],35),''); $pubdate = date('D, j M Y',strtotime($item['pubdate'])); $out[] = '<div id="repost"><h3>'.$title.'</h3><h4 style="color:#ece8de;line-height:0.8px; padding-left:5px">'.$pubdate.'</h4><p>'.$desc.'</p><a href="express_pick.php?action=display&id='.$href.'&nme='.$title.'" " title="'.$title.'">[Read more]</a></div><br /> '; }
echo ($out) /* ? "<ul>\n".join("\n",$out)."\n</ul>"*/ ? join("\n",$out) : '';
// sorts feed array based on published date (used with usort) // ------------------------------------------------------------- function date_cmp($a, $b) { $atime = (empty($a['date_timestamp'])) ? strtotime($a['dc']['date']) : $a['date_timestamp'];
$btime = (empty($b['date_timestamp'])) ? strtotime($b['dc']['date']) : $b['date_timestamp'];
if ($atime == $btime) return 0; return ($atime > $btime) ? -1 : 1; }
// Limits the length of the description item function summary($content, $limit){
$content = explode(' ',$content);
for($i=0; $i<$limit; $i++){
$summary[$i] = $content[$i];
}
$summary = implode(' ', $summary).'..';
return $summary;
} ?>
I put some timers in there to see what was happening and once it got to the point of creating the master array (as shown below) it would take between 4-5 minutes to output. However, once this had happened I could run the code again and it would take less than 1 second.
If I left the page and came back about 10 mins later it would again take 4-5 minutes to produce the results.
PHP Code:
/ loop thru all urls & merge feeds into master array foreach ( $urls as $url ) { $rss = fetch_rss($url); if (!$rss) continue; $items = array_merge($items, $rss->items); }
I basically ran the same script on another page and had this page automatically served by a cron set for 15 min intervals - but it made no difference.
Any ideas?
|