<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Caching external data in PHP</title>
	<atom:link href="http://www.gayadesign.com/diy/caching-external-data-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gayadesign.com/diy/caching-external-data-in-php/</link>
	<description>PHP, CSS, xhtml, javascript / jquery tutorials</description>
	<lastBuildDate>Sat, 18 Feb 2012 11:01:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Alex</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-126055</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Thu, 02 Feb 2012 13:35:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-126055</guid>
		<description>Can u plz tell how can we use it other than last.fm data?
How if we have established curl data and want to cache it?</description>
		<content:encoded><![CDATA[<p>Can u plz tell how can we use it other than last.fm data?<br />
How if we have established curl data and want to cache it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ruiz</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-117382</link>
		<dc:creator>Ruiz</dc:creator>
		<pubDate>Thu, 12 Jan 2012 12:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-117382</guid>
		<description>Hi,

I want this code to work for me :) but i do not want to strip or change the file that is beeing fetched and saved in the local file.
Is it possible to change the stripAndSaveFile function to only save the content in the local file instaed of stripping and changing?

Another thing.. Is it possible to have the output xml decoded to json and saving it locally? so you can have a callback function to grab the data?

Kind regards,
R</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I want this code to work for me :) but i do not want to strip or change the file that is beeing fetched and saved in the local file.<br />
Is it possible to change the stripAndSaveFile function to only save the content in the local file instaed of stripping and changing?</p>
<p>Another thing.. Is it possible to have the output xml decoded to json and saving it locally? so you can have a callback function to grab the data?</p>
<p>Kind regards,<br />
R</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-48440</link>
		<dc:creator>Chad</dc:creator>
		<pubDate>Wed, 17 Aug 2011 18:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-48440</guid>
		<description>Thank you so much for this. Not only is this a great example for caching data, but it&#039;s also an excellent intoduction to Classes as well.

I have added one simple little function to the class:

	function getData() {
		return file_get_contents($this-&gt;filePath);
	}

$caching-&gt;getData() will then return the contents of the file.
I&#039;m working with json data so wanted the raw text. 
For people working with XML, they may want to change the line to:
simplexml_load_file($this-&gt;filePath);
as per the post above.

Thanks again for a great tutorial!</description>
		<content:encoded><![CDATA[<p>Thank you so much for this. Not only is this a great example for caching data, but it&#8217;s also an excellent intoduction to Classes as well.</p>
<p>I have added one simple little function to the class:</p>
<p>	function getData() {<br />
		return file_get_contents($this-&gt;filePath);<br />
	}</p>
<p>$caching-&gt;getData() will then return the contents of the file.<br />
I&#8217;m working with json data so wanted the raw text.<br />
For people working with XML, they may want to change the line to:<br />
simplexml_load_file($this-&gt;filePath);<br />
as per the post above.</p>
<p>Thanks again for a great tutorial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-28643</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Fri, 03 Jun 2011 19:16:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-28643</guid>
		<description>Thank you for this tutorial. But I noticed that you left out a very important step -&gt; getting the cached data rather than the uri call every time.

$data = simplexml_load_file($filepath);

Putting this in, instead of asking for $caching-&gt;getExternalInfo() greatly sped up my script ;)

It was probably just me, but I&#039;m hoping that this comment will help others.

Thank you!</description>
		<content:encoded><![CDATA[<p>Thank you for this tutorial. But I noticed that you left out a very important step -&gt; getting the cached data rather than the uri call every time.</p>
<p>$data = simplexml_load_file($filepath);</p>
<p>Putting this in, instead of asking for $caching-&gt;getExternalInfo() greatly sped up my script ;)</p>
<p>It was probably just me, but I&#8217;m hoping that this comment will help others.</p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Breklin</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-20401</link>
		<dc:creator>Breklin</dc:creator>
		<pubDate>Wed, 06 Apr 2011 19:57:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-20401</guid>
		<description>Thank you very much for this informative tutorial. I have a question. I&#039;m dealing with this really dumb API that makes you call for &#039;states.xml&#039; in a given country which I then loop through a nested foreach where another call to &#039;cities.xml&#039; is made for each state via nested loop.

This is used to create a drop down from an external service to get all the states-&gt;cities they offer a service in. The crappy part, and the reason I am looping over the &#039;cities.xml&#039; api call, is that each set of cities within a state must be called as an individual file that pulls in the cities for the currently looping state based on that state&#039;s ID...major resource suck as the cities API call has to be made over 51 times (1 for each state).

I have modified your code for the stripFileAndSave function to read:
[code]
function stripAndSaveFile($xml,$first,$second,$attr1,$attr2) {
					// put the artist in an array
					$createForEachParam = $xml-&gt;$first-&gt;$second;
					
					// build our own XML based on the information we require
					$output = new SimpleXMLElement(&quot;&lt;$first&gt;&lt;/$first&gt;&quot;);
					
					// create new xml file
					$insert = $output-&gt;addChild($second);
					$insert = $output-&gt;addChild(&quot;id&quot;,$second[$attr1]-&gt;id);
					$insert = $output-&gt;addChild(&quot;name&quot;,$second[$attr2]-&gt;name);
					
					file_put_contents($this-&gt;filePath, $output-&gt;asXML());

		}
[/code]

This is more of a generic class but still targeted toward the APIs I am calling as they have parents and children with the children having attributes (id and name).

Is this class capable of caching different files? In my case, I&#039;m looking at up to 52 files. I have it set to a 3 hour interval to ensure that if new states or cities have been added, the application pull the correct list.</description>
		<content:encoded><![CDATA[<p>Thank you very much for this informative tutorial. I have a question. I&#8217;m dealing with this really dumb API that makes you call for &#8216;states.xml&#8217; in a given country which I then loop through a nested foreach where another call to &#8216;cities.xml&#8217; is made for each state via nested loop.</p>
<p>This is used to create a drop down from an external service to get all the states-&gt;cities they offer a service in. The crappy part, and the reason I am looping over the &#8216;cities.xml&#8217; api call, is that each set of cities within a state must be called as an individual file that pulls in the cities for the currently looping state based on that state&#8217;s ID&#8230;major resource suck as the cities API call has to be made over 51 times (1 for each state).</p>
<p>I have modified your code for the stripFileAndSave function to read:</p>
<pre class="brush: plain; title: ; notranslate">
function stripAndSaveFile($xml,$first,$second,$attr1,$attr2) {
					// put the artist in an array
					$createForEachParam = $xml-&gt;$first-&gt;$second;

					// build our own XML based on the information we require
					$output = new SimpleXMLElement(&quot;&lt;$first&gt;&lt;/$first&gt;&quot;);

					// create new xml file
					$insert = $output-&gt;addChild($second);
					$insert = $output-&gt;addChild(&quot;id&quot;,$second[$attr1]-&gt;id);
					$insert = $output-&gt;addChild(&quot;name&quot;,$second[$attr2]-&gt;name);

					file_put_contents($this-&gt;filePath, $output-&gt;asXML());

		}
</pre>
<p>This is more of a generic class but still targeted toward the APIs I am calling as they have parents and children with the children having attributes (id and name).</p>
<p>Is this class capable of caching different files? In my case, I&#8217;m looking at up to 52 files. I have it set to a 3 hour interval to ensure that if new states or cities have been added, the application pull the correct list.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-19457</link>
		<dc:creator>andrew</dc:creator>
		<pubDate>Tue, 22 Mar 2011 01:14:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-19457</guid>
		<description>figured it out, the file was loading with all the file content on one line, weird.</description>
		<content:encoded><![CDATA[<p>figured it out, the file was loading with all the file content on one line, weird.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-19455</link>
		<dc:creator>andrew</dc:creator>
		<pubDate>Tue, 22 Mar 2011 00:39:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-19455</guid>
		<description>So I got the code to work, but I had to take out all the comments out in the class. Whenever I leave the comments in it throws an error, does anyone know why?</description>
		<content:encoded><![CDATA[<p>So I got the code to work, but I had to take out all the comments out in the class. Whenever I leave the comments in it throws an error, does anyone know why?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Another night spent coding in PHP &#8211; Muskblog</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-11934</link>
		<dc:creator>Another night spent coding in PHP &#8211; Muskblog</dc:creator>
		<pubDate>Thu, 30 Sep 2010 23:18:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-11934</guid>
		<description>[...] but it shouldn&#8217;t be that big of a deal to cache the results of the API requests as XML. Other people have done this, it should work fine. Caching is a little out of my area of expertise, usually I&#8217;m working in [...]</description>
		<content:encoded><![CDATA[<p>[...] but it shouldn&#8217;t be that big of a deal to cache the results of the API requests as XML. Other people have done this, it should work fine. Caching is a little out of my area of expertise, usually I&#8217;m working in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Muskie</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-11920</link>
		<dc:creator>Muskie</dc:creator>
		<pubDate>Thu, 30 Sep 2010 07:55:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-11920</guid>
		<description>This appears to be close to what I want to do.  I&#039;m making a mashup and I make a lot of API calls etc. etc.  Last.FM is one of the services I&#039;m using naturally.  Amazon is the other main API I&#039;m using.  Both can give my XML or I can get the XML from their response easy enough, so I was just going to cache the entire response, now I might think a little more.  I&#039;m mainly interested in URLs to images or more information...

It is late and implementing caching to speed up my class and api calls is my next big goal.  Gotta do more research first I think.  Thanks again for writing this tutorial.

Cheers,</description>
		<content:encoded><![CDATA[<p>This appears to be close to what I want to do.  I&#8217;m making a mashup and I make a lot of API calls etc. etc.  Last.FM is one of the services I&#8217;m using naturally.  Amazon is the other main API I&#8217;m using.  Both can give my XML or I can get the XML from their response easy enough, so I was just going to cache the entire response, now I might think a little more.  I&#8217;m mainly interested in URLs to images or more information&#8230;</p>
<p>It is late and implementing caching to speed up my class and api calls is my next big goal.  Gotta do more research first I think.  Thanks again for writing this tutorial.</p>
<p>Cheers,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dolido</title>
		<link>http://www.gayadesign.com/diy/caching-external-data-in-php/comment-page-1/#comment-9432</link>
		<dc:creator>dolido</dc:creator>
		<pubDate>Sun, 16 May 2010 14:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.gayadesign.com/?p=349#comment-9432</guid>
		<description>thanks 4 this post.</description>
		<content:encoded><![CDATA[<p>thanks 4 this post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

