PHP RSS Caching

I was looking for a solution for caching RSS feeds in PHP. I planned to parse with the RSS Magpie parser (http://magpierss.sourceforge.net/ ). But then how can I use feed caching (in case the feed provider does not allow me to read the same feed, etc.)?

Sincerely.

+3
source share
4 answers
  • You get a feed. Save the results to a database or file (serialize ()).
  • When it’s time to upload the feed again,
  • Check if the file exists if it is not created and updated
  • If the file exists, check the db or file timestamp.
  • (, 20 ), , .
  • , (, 20 ).

Voila.

+3

, , , wget.

/cache

.

, a) . b) c) cron

, , .

+2

@Byron Whitlock , . MagPie. rss2html.php, HTML- RSS fetch, HTML-, . include ( "rss2html.php" ), HTML. RSS HTML. :

<?php 
            $hashfromURL = hash("md5",$url);
            $cachefile = "cache/rss/".$hashfromURL.".html";

            $cachetime = 5*60; //5 minuta TODO:Pri deployment-u povecati na sat-dva.
            //Serviraj is kesha ako je mladji od $cachetime 
            if(file_exists($cachefile) && (time() - filemtime($cachefile) < $cachetime ))
            {
                include($cachefile);
                echo "RSS ucitan iz kesha!";

            }
            else{//Ucitaj RSS ponovo    

                $XMLfilename = $url;

                //Pocni dump buffera
                ob_start();

                include("rss2html.php");//HTML parsiran sadrzaj RSS-a

                //Otvori kesh fajl za pisanje
                $fp = fopen($cachefile, 'w');

                //Sacuvaj sadrzaj izlaznog buffer-a u fajl
                fwrite($fp, ob_get_contents());

                //zatvori fajl
                fclose($fp);

                //Posalji izlaz na browser
                ob_end_flush(); 
                echo "RSS osvjezen - feed ponovo ucitan!";
            }

    ?>
+1
source

Is a hitch created in the cache? Why not use this? I personally use SimplePie. Here is the caching document for SimplePie:

http://simplepie.org/wiki/faq/how_does_simplepie_s_caching_http_conditional_get_system_work

0
source

Source: https://habr.com/ru/post/1759230/


All Articles