PHP RSS XML newsreader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ARGENTINA

    PHP RSS XML newsreader

    Hi all,
    I hope someone can help,
    I've made an RSS xml newsreader in flash that reads rss files from
    syndicated news sites, but a lot of these companies get a bit upset if
    you access the feed too often.
    What I'm hoping someone has is a small php script that will goto
    "whatever" site every 30 mins and make a copy os the rss file to the
    local server where my site is hosted.
    All I need the php script to do is make a copy of it, not parse it.
    Thanks in advance if you can help.

    Marcos

    pd: please include the full script due I am new with php.
  • Janwillem Borleffs

    #2
    Re: PHP RSS XML newsreader

    ARGENTINA wrote:[color=blue]
    > Hi all,
    > I hope someone can help,
    > I've made an RSS xml newsreader in flash that reads rss files from
    > syndicated news sites, but a lot of these companies get a bit upset if
    > you access the feed too often.
    > What I'm hoping someone has is a small php script that will goto
    > "whatever" site every 30 mins and make a copy os the rss file to the
    > local server where my site is hosted.
    > All I need the php script to do is make a copy of it, not parse it.
    > Thanks in advance if you can help.
    >
    > Marcos
    >
    > pd: please include the full script due I am new with php.[/color]

    Use a crontab like the following:

    30 * * * * wget -O feed.html http://rss.feed.url


    JW



    Comment

    • MikeSoja

      #3
      Re: PHP RSS XML newsreader

      On 16 Jan 2005 06:57:01 -0800, sjprec@yahoo.co m (ARGENTINA) posted:
      [color=blue]
      >Hi all,
      >I hope someone can help,
      >I've made an RSS xml newsreader in flash that reads rss files from
      >syndicated news sites, but a lot of these companies get a bit upset if
      >you access the feed too often.
      >What I'm hoping someone has is a small php script that will goto
      >"whatever" site every 30 mins and make a copy os the rss file to the
      >local server where my site is hosted.
      >All I need the php script to do is make a copy of it, not parse it.
      >Thanks in advance if you can help.[/color]
      [color=blue]
      >Marcos[/color]
      [color=blue]
      >pd: please include the full script due I am new with php.[/color]

      Here's the way I do it...

      define(LOCAL, "0");
      define(REMOTE, "1");

      $location = LOCAL;
      $xml_file = array("local.xm l", "remote.xml ");
      $cur_time = date("U");
      $xml_file_time = filemtime($xml_ file[LOCAL]);
      if ($cur_time - $xml_file_time > 60 * 30) //every 30 minutes
      $location = REMOTE;

      $fp = fopen($xml_file[$location],"r");

      if (!$fp) { //if first open fails, open previously saved file.
      $location = LOCAL;
      $fp = fopen($xml_file[LOCAL],"r");
      }
      elseif ($location) //or also open remote file, too
      $fplocal = fopen($xml_file[LOCAL],"w");
      /*
      note the local file is not opened for a write if the remote file
      could not be opened, so we always have the local file to read
      */
      while ($data = fread($fp, 4096)) {
      if ($fplocal and $data)
      fwrite($fplocal , $data, 4096);
      xml_parse($xml_ parse, $data, feof($fp));
      }

      if ($fp)
      fclose($fp);

      if ($fplocal)
      fclose($fplocal );

      //--------Mike Soja

      Comment

      Working...