I just started using SimpleXML to get a feed and display data from that XML feed on one of my webpages. See my first post https://stackoverflow.com/questions/5925368/how-to-use-the-weather-gov-xml-feed-on-a-website I have a basic knowledge of PHP so I may be missing something basic.
If I understand what is happening correctly, every time someone looks at my page before it displays the php, the script first has to go and get the feed. Then it does what I have asked it to do with the feed and then displays the page.
I would think everything would be faster if I was to cache either the feed or formatted the feed and cache that. Which is better caching the raw feed or format the feed and cache the result? How do I go about caching either?
I am hoping that someone can point me in the direction of a tutorial that will teach me how to cache things with php or maybe someone has some example code that I could learn from and/or adapt for my project?
Thanks.
Google “simple php cache tutorial” or look at this one.
Instead of echo or print-ing text to the screen as you probably are now, build up a variable using the technique of string concatenation like so:
Essentially you ought to cache a segment of html, which you then use PHP to include at the correct place in your webpages, probably using file_get_contents();
The logic in the tutorial will tell you how to check the date of the cache and then decide to a) go and refresh the xml and recreate the cache or b) lift up and display the cached file