Cache feed or finished page?

I just started using SimpleXML to retrieve a feed and display data from this XML feed on one of my web pages. See my first post https://stackoverflow.com/questions/5925368/how-to-use-the-weather-gov-xml-feed-on-a-website I have basic PHP knowledge, so I can skip that- that is the main thing.

If I understand what is happening correctly, every time someone looks at my page before he displays php, the script must go first and get the feed. Then he does what I asked him to work with the feed, and then displays the page.

I would think that everything will be faster if I cache the feed or format the feed and cache. What is the best way to cache the source channel or format the feed and cache the result? How can I use caching?

I hope that someone can point me towards a tutorial that will teach me how to cache things using php, or maybe someone has an example of code that I could study and / or adapt for my project?

Thank.

+3
source share
3 answers

Google "simple php cache tutorial" or see this .

Instead of echoing or printing text on the screen, as you probably are now, create a variable using the string concatenation technique as follows:

$html = '<h3>Weather View</h3>';

foreach( element in your xml feed){
$html .= 'Some more information';
}
//then when done
file_put_contents('weather_cache.txt', $html );

, html, PHP -, , file_get_contents();

, , : ) xml b)

+2

PHP , , , APC (( )) ( , /). - redistogo (), -.

, , , - php, script . , , .

, (redis). ( , , script , ()...), - cronjob. , cronjobs, , http://www.onlinecronjobs.com/.

, , . ? ?

, . , .

, , , SETEX . -, . Predis, redistogo .

, - , , php , , - , / ?

redis. -. Google, .

+1
0
source

All Articles