To hide an RSS feed
You can save resources by putting the converted stream in HTML form in a file, rather than parsing the XML and converting it to HTML each time you view it.
However, this cache file should be updated automatically and regularly, for example, every hour, as in the code example below.
On the web page representing the stream, the normal code for calling RSSLIB (for example, URL) will be replaced:
<?php
require_once("rsslib.php");
$url = "https://www.iqlevsha.ru/rss.xml";
echo RSS_Display($url, 15, false, true);
?>
By the following code:
<?php $cachename = "rss-cache-tmp.php"; $url = "https://www.iqlevsha.ru/rss.xml"; if(file_exists($cachename)) { $now = date("G"); $time = date("G", filemtime($cachename)); if($time == $now) { include($cachename); exit(); } } include("rsslib.php"); $cache = RSS_Display($url, 15, false, true);
file_put_contents($cachename, $cache); echo $cache; ?>
For a different update frequency, the date format () and comparison test will be changed.
For example, to update every ten minutes, the format would be:
$time = date("i", filemtime($cachename));
and the benchmark will become:
if(intval($time) / 10 == intval($now) / 10)
See demonstration: Caching an RSS feed.
Download the archive on the article page: RSS Reader.