daq Posted January 8, 2009 Share Posted January 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 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.... Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732690 Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732692 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732694 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732699 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 Why not try curl or for a simpler route, file_get_contents Curl is quicker, but file_get_contents is easier =) Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732711 Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732726 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 then their server is doing something wrong. if you load the RSS feed into a browser, does it not show the old data? No, it shows updated information. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732752 Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 is it a public link i can look at? Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732773 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 Why not try curl or for a simpler route, file_get_contents Curl is quicker, but file_get_contents is easier =) Interesting. Using curl, the feeds that showed old content, don't show any data at all. I wonder if a timeout or something similar causes web host to use cache? Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732822 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 is it a public link i can look at? Its a closed site, but the problem is not reproducible 100% of the time and my host, 1&1, completely blocks all error messages so you wouldn't see much more than outdated rss feeds. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732830 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732845 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 Wow. I was wrong. Even after I updated the links, I'm still getting old data even with curl. Where the hell can it be coming from? Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732863 Share on other sites More sharing options...
daq Posted January 8, 2009 Author Share Posted January 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140042-cache-fopen/#findComment-732919 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.