Hi there. Sorry if this question has already been asked. Its a bit abstract so I couldn't think what to search for.
Basically, I have a small script which downloads a remote XML file, strips out some relevant data, and displays it in HTML. All well and good, but the thing is that the script downloads the XML file each time the page is loaded, which means that potentially, the XML file could be downloaded rather a lot of times, creating excessive bandwidth usage and possible having my server's IP banned from the XML source. Being new to PHP, I don't really know the best way of circumventing this problem. I would have thought that having some sort of background script to keep a server copy of the XML file updated, and then having the script retrieve its version from there would be a reasonable approach. Is this possible? Can a script be set some how to run constantly in the background? Alternatively, perhaps I could somehow have the script check a timestamp on the server copy of the XML file, and if it is old, instruct the server to refresh it...although I don't know how the script would know that the XML file was old without downloading a newer version and checking timestamps.
Any ideas on this would be much appreciated.
shaw2thefloor
Server copy of XML file
Moderator: General Moderators
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: Server copy of XML file
You could create a cron job for the script to be fired off every so often to download the new xml source. Or you could have your script check the creation time of a local version of the xml document. If it's so many minutes old, download a new copy.
-Andy
-Andy
-
shaw2thefloor
- Forum Newbie
- Posts: 2
- Joined: Fri Oct 10, 2008 12:35 pm
Re: Server copy of XML file
Yeah, that's a good idea. Just get the script to check and update if necessary. Thanks for the tip.