Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with RSS caching
Old 11-06-2007, 06:01 PM Help with RSS caching
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
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('
Dj 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?
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-27-2008, 08:08 AM Re: Help with RSS caching
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Thanks. Worked it out.
scrobins is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with RSS caching
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10587 seconds with 12 queries