Caching xml files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
radu
Forum Newbie
Posts: 4
Joined: Mon Jun 05, 2006 2:12 am

Caching xml files

Post by radu »

twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is my code. What is basically does it cahes an xml file, if the access date of the file does not correspond to
the current date, then the content of the file is updated with the content of the file from  http://www.bnm.org/apps/ofexch_xml.jsp.
   This code works fine if i'm on dial-up connection, the problem appears when i run this script on a computer which is a part of network. The warning is something like "could not open stream...". I guess  the problem is related to the firewall. Can any one tell a method of caching a xml file in this circumstaces.

Code: Select all

<?.............
$url="http://www.bnm.org/apps/ofexch_xml.jsp";
$cachefile="./some.xml";

if(file_exists($cachefile)) {
   $date_str = getdate(fileatime($cachefile));
   $year = $date_str["year"];
   $mon = $date_str["mon"];
   $mday = $date_str["mday"];
}else echo "File doesn't exist";

$date_string = "$mday/$mon/$year";
$cur_date=date("j/n/Y");

if($date_string!=$cur_date){
   $xml = file_get_contents($url);
   $fp=fopen($cachefile,"w");
   fwrite($fp,$xml);
   fclose($fp);
   //if(!copy($url,$cachefile )) die("Can't copy file" );
}
..........?>
twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Can you post the exact error? It doesn't sound like it's got anything to do with 56k vs. Cable/DSL.

It sounds like PHP doesn't have permissions to open (or create) the cached file.
Post Reply