Jump to content

Cache fopen


daq

Recommended Posts

I created an online rss reader using lastRSS http://lastrss.oslab.net/.

Basically, all it does is read the xml from rss feed using fopen and then parses it.

 

It works great but occasionally, it gets stuck on rss items from several months ago and refuses to update.

I don't use caching of any kind so I have no idea where old data comes from.

 

Since I'm out of ideas I'm coming up with insane theories to justify this behavior. Is it possible my web host is caching fopen requests? Is that even possible?

 

Any help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/
Share on other sites

You can set the page to not cache using header.

 

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

?>

 

So each time the page is loaded it must be refreshed....

 

Sorry, I guess I wasn't specific enough. I didn't mean browser cache. I meant server side cache for fopen.

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732694
Share on other sites

it is possible that they are caching requests. try adding a unique value to the end:

 

<?php
  $url = "http://hostname.com/feed.rss";
  //Try to stop caching
  $url  = $url . '?_='.time();
  fopen($url,'r');
  //etc
?>

 

This is a great solution that should've worked, but I'm still getting outdated data.

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732699
Share on other sites

it is possible that they are caching requests. try adding a unique value to the end:

 

<?php
  $url = "http://hostname.com/feed.rss";
  //Try to stop caching
  $url  = $url . '?_='.time();
  fopen($url,'r');
  //etc
?>

 

This is a great solution that should've worked, but I'm still getting outdated data.

 

then their server is doing something wrong. if you load the RSS feed into a browser, does it not show the old data?

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732726
Share on other sites

OK, I figured it out with the help of Curl. Both RSS feeds that were showing old data changed address and were returning a 301, page moved permanently. I'm surprised the script worked at all. And I still don't know where the old data came from.

 

At least the problem is gone.

Thanks to everyone for the help!

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732845
Share on other sites

I'm sorry for posting a million things, but this simple test script, seems to work without problems:

<?php
$rss_url = "http://feedproxy.google.com/Explosm";

$f = curl_init();
curl_setopt($f, CURLOPT_URL,$rss_url);
curl_setopt($f, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($f, CURLOPT_RETURNTRANSFER, true);
curl_setopt($f, CURLOPT_VERBOSE, true);


if ($rss_content = curl_exec($f))
{
echo $rss_content;
}
curl_close($f);

?>

 

This is the same code I use in my RSS reader which is showing old data.

Link to comment
https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732919
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.