Page 1 of 1

Caching xml files

Posted: Mon Jun 05, 2006 1:06 pm
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]

Posted: Mon Jun 05, 2006 4:46 pm
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.