Jump to content

simplexml_load_file doesn't reload file


DjMikeS

Recommended Posts

Hi all,

 

I've got this script to read an rss feed and display it on my website. I only want it to display the first 10 records, and leave out any items that don't belong to the "nieuws" (in english: news) category.

 

So far so good though I think it can be done a little nicer...

The real problem is that it doesn't seem to reload the feed when I reload my website...I still see the old news items while the feed has been updated...

 

Do you know how to solve this?

 

My code:

<?php
try {
	$strFeed = "http://feeds.feedburner.com/tweakers/mixed";
	if (!$sxml = simplexml_load_file($strFeed)) {
		$strError = "RSS feed not available at this moment";
		Throw New Exception();
	}

	$i = 0;
	foreach ($sxml->channel->item as $item){
		if (stristr($item->category, 'Nieuws') AND $i < 10) {
			echo "<li><b><a href=\"$item->link\">$item->title</a></b></li>\n";
		$i++;
		}
	}
	unset ($sxml);
}

catch (Exception $e) {
	echo $strError;
}
?>

Link to comment
Share on other sites

Thnx tmallen, I know feedburner isn't limiting my ip, because when I open the feed in my browser I can refresh as much as I like...

 

I think php is caching the feed or something...

The other solution would be to create a cronjob that automagically downloads the correct file every hour or so...but I would like to have it in sync....

 

edit:

I read something about the headers so I added this to my site:

 

header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // time in the past

header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . 'GMT');

header('Cache-Control: no-cache, must-revalidate');

header('Pragma: no-cache');

header('Content-Type: text/html');

 

But no luck yet....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.