PHP RSS XML newsreader

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.


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

Re: PHP RSS XML newsreader

On 16 Jan 2005 06:57:01 -0800, (ARGENTINA) posted:

Quoted text here. Click to load it

Here's the way I do it...

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

$location = LOCAL;
$xml_file = array("local.xml", "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)

if ($fplocal)

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

Re: PHP RSS XML newsreader

Quoted text here. Click to load it

Use a crontab like the following:

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


Site Timeline