RSS, PHP and how to actually trigger the refresh of the RSS feed

Discussion in 'PHP' started by PoPSiCLe, Feb 24, 2009.

  1. #1
    Well, ok - I have a webpage, where I intend to create an RSS feed for the news-items on the front page.

    The news items on the front page is updated via the admin panel on the page (ie, manually) whenever a person with admin rights decide to write something.

    I have a working rss.php-file, which outputs a valid rss-feed - the problem I'm having is that whenever I update the front page with news, the rss-feed doesn't "trigger" - I'm assuming that is because I actually have to use the rss.php-file to generate the feed before it is updated. Not very user-friendly, mind.

    What I'm looking for is a way to either include the script I'm already using in the posting of the news from the admin page, or trigger the rss.php file to run and generate an updated feed whenever I post stuff.

    I've been looking at RSS-tutorials and whatnot for most of the night, but haven't really found anything about how to trigger, or refresh, the actual file - most tutorials are very generic, and doesn't really cover what I'm after.

    I'll post a copy of the actual script I'm using, obfuscating some items for security purposes, but the script itself is the same:

    <?php
    include ('db_login.php');
    $news_items = "SELECT * FROM $news WHERE (ni_expire>='$date' OR ni_expire='0000-00-00') ORDER BY `ni_date` DESC LIMIT 15";
    $result=mysql_query($news_items);
    $num=mysql_numrows($result);
    
        $channel = array("title"        => "News",
                         "description"  => "An RSS-feed.",
                         "link"         => "http://www.whateveryourdomain.nothing");
    
    
        $output = '<?xml version="1.0" encoding="utf-8" ?>';
        $output .= '<rss version="2.0">';
        $output .= "<channel>";
        $output .= "<title>" . $channel["title"] . "</title>";
        $output .= "<description>" . $channel["description"] . "</description>";
        $output .= "<link>" . $channel["link"] . "</link>";
    
    $i=0;
    while ($i < $num) {
    $user_array = mysql_fetch_array($result,MYSQL_BOTH);
    
            $output .= "<item>";
            $output .= "<title>" . $user_array["heading"] . "</title>";
            $output .= "<description>" . $user_array["content"] . "</description>";
            $output .= "</item>";
    $i++;
    }
    
        $output .= "</channel>";
        $output .= "</rss>";
        header("Content-Type: application/rss+xml; charset=utf-8");
        echo $output;
    ?>
    Code (markup):
     
    PoPSiCLe, Feb 24, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you misunderstand how RSS works. It's up to the client to fetch a new version of the feed when it wants to.
     
    SmallPotatoes, Feb 25, 2009 IP
  3. imchandan

    imchandan Guest

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    exactly,
    when client(user)'s browser requests for RSS from your site. it then executes php file to get latest feeds.
     
    imchandan, Feb 25, 2009 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    I got that after I asked the initial question :D

    I actually thought that was how it was done, but my chosen feed-reader wouldn't update the feed, it seemed, no matter what I did - seemed there was a problem with the feed-reader, and not the feed. Testing in Google Reader, and it worked fine.
     
    PoPSiCLe, Feb 26, 2009 IP