<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ali Qureshi&#039;s Blog &#187; PHP Classes</title>
	<atom:link href="http://www.parorrey.com/blog/tag/php-classes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parorrey.com/blog</link>
	<description>random bits on web development</description>
	<lastBuildDate>Tue, 07 Sep 2010 10:17:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://www.parorrey.com/blog/?pushpress=hub'/>
		<item>
		<title>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:06:45 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[mediaRSS]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[RSS Parser]]></category>
		<category><![CDATA[SimplePie]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=145</guid>
		<description><![CDATA[If you ever faced a scenario where you had to parse the rss feed with image thumbnails placed inside &#8220;enclosure&#8221; tags, SimplePie is the perfect solution. In fact SimplePie can parse mediaRSS. There are several other php classes such as Magpie which can do the job as well. Magpie can parse rss2.0 enclosure but not [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you ever faced a scenario where you had to parse the rss feed with image thumbnails placed inside &#8220;enclosure&#8221; tags, <a href="http://simplepie.org/" target="_blank"><strong>SimplePie</strong></a> is the perfect solution. In fact SimplePie can parse mediaRSS. There are several other php classes such as Magpie which can do the job as well. Magpie can parse rss2.0 enclosure but not mediaRSS and I had hard time getting enclosure parsed with Magpie. After spending hours, I tried Simple Pie and it worked like a charm.  </p>
<p>SimplePie is a fast and feature rich PHP class that is very simple to use.  </p>
<p>In few steps, you can use SimplePie to retrieve and parse any RSS or Atom feeds and display them on any PHP website. SimplePie also allows you to incorporate any type of data from any number of feeds. Here&#8217;s how you can setup SimplePie in three steps:</p>
<ul>
<li> <a href="http://simplepie.org/downloads/" target="_blank">Download SimplePie</a> and uncompress it    </li>
<li> Place the &#8220;simplepie.inc&#8221; into a your &#8220;includes&#8221; folder under root directory of your website and include it into your calling script    </li>
<li> Create a directory named &#8220;cache&#8221; (also in the web-accessible root directory) and make sure that it&#8217;s writable by the server (i.e., CHMOD to 755, 775, or 777)</li>
</ul>
<p>Here&#8217;s the sample code to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SIMPLEPIE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/path/to/simplepie.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>SIMPLEPIE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//include the simplepie class</span>
  <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.parorrey.com/blog/feed/'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// bake a new pie</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// provide feed url</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cache_duration</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// specify cache duration in seconds</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// text/html utf-8 character encoding</span>
  <span style="color: #000088;">$check</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// script initialization check</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$check</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_items</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$enclosure</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_enclosure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
   <span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$enclosure</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_link</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; 
       alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$rss_feed</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;div class=&quot;rssItem&quot;&gt;
  &lt;span class=&quot;date&quot;&gt;
 '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j F Y @ g:i a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;
  &lt;h3&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_permalink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; 
       title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;
      target=&quot;_blank&quot; rel=&quot;no-follow&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'
       &lt;br/&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$thumb</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/h3&gt;		
&lt;p&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_description</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;spacer dash&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>      
&nbsp;
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div id=&quot;rssNews&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$rss_feed</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>SimplePie also allows you to merge different rss feeds into one single stream.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'http://your-domain1.com/your-feed1/'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'http://your-domain2.com/your-feed2/'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'http://your-domain3.com/your-feed3/'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here is where the cache directory should exist if you are using the default cache location: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>your<span style="color: #339933;">/</span>feed_page<span style="color: #339933;">.</span>php
<span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>your<span style="color: #339933;">/</span>cache<span style="color: #339933;">/</span>
<span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>simplepie<span style="color: #339933;">/</span>way<span style="color: #339933;">/</span>deep<span style="color: #339933;">/</span>in<span style="color: #339933;">/</span>directory<span style="color: #339933;">/</span>simplepie<span style="color: #339933;">.</span>inc</pre></div></div>

<p>Please note that using ./cache (dot-slash-cache) means that the cache directory will be relative to the page that&#8217;s calling SimplePie, not SimplePie itself.
</p>
<p>Hope that helps.</p>
<p> Cheers! </p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</title>
		<link>http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/</link>
		<comments>http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 10:45:27 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[MagpieRSS]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[RSS feeds]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=15</guid>
		<description><![CDATA[MagpieRSS is a XML-based RSS parser in PHP. MagpieRSS supports most RSS versions including modules and namespaces. Magpie RSS also supports caching which is kind a must while parsing any feed because you don’t want to fetch the feed for every hit on your website and risk getting banned. Although Magpie RSS is really useful [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/' rel='bookmark' title='Permanent Link: How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie'>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/' rel='bookmark' title='Permanent Link: Parsing News Feed using PHP &#038; MagpieRSS and making it scroll'>Parsing News Feed using PHP &#038; MagpieRSS and making it scroll</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong><a href="http://magpierss.sourceforge.net/" target="_blank">MagpieRSS</a></strong> is a XML-based RSS parser in PHP. <strong>MagpieRSS</strong> supports most RSS versions including modules and namespaces. Magpie RSS also supports caching which is kind a must while parsing any feed because you don’t want to fetch the feed for every hit on your website and risk getting banned.</p>
<p>Although <strong>Magpie RSS</strong> is really useful and I&#8217;ve used it in many projects, one of the feature which is missing from Magpie is setting different cache ages. I had to setup few feeds in a website recently and set different caching age for different feeds. If you are facing similar problem, read on to check the solution. </p>
<p>I made few following changes in the code of function <strong>function fetch_rss</strong>  inside  &#8216;rss_fetch.php&#8217; file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;">/*added 2nd parameter for setting different cache age and set existing MAGPIE_CACHE_AGE as default */</span>
<span style="color: #000000; font-weight: bold;">function</span> fetch_rss <span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$magpie_cache_age</span><span style="color: #339933;">=</span>MAGPIE_CACHE_AGE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// initialize constants</span>
    init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fetch_rss called without a url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if cache is disabled</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>MAGPIE_CACHE_ON <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// fetch file, and parse it</span>
        <span style="color: #000088;">$resp</span> <span style="color: #339933;">=</span> _fetch_remote_file<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_success<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$resp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> _response_to_rss<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$resp</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to fetch <span style="color: #006699; font-weight: bold;">$url</span> and cache is off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #666666; font-style: italic;">// else cache is ON</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Flow</span>
        <span style="color: #666666; font-style: italic;">// 1. check cache</span>
        <span style="color: #666666; font-style: italic;">// 2. if there is a hit, make sure its fresh</span>
        <span style="color: #666666; font-style: italic;">// 3. if cached obj fails freshness check, fetch remote</span>
        <span style="color: #666666; font-style: italic;">// 4. if remote fails, return stale object, or error</span>
&nbsp;
       <span style="color: #666666; font-style: italic;">//we are not using constant MAGPIE_CACHE_AGE rather using parameter age **added by parorrey**</span>
	   <span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RSSCache<span style="color: #009900;">&#40;</span> MAGPIE_CACHE_DIR<span style="color: #339933;">,</span> <span style="color: #000088;">$magpie_cache_age</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that was it. Now you can call the function <strong>fetch_rss</strong> with the cache age different than the default MagpisRSS cache age defined in constant <strong>MAGPIE_CACHE_AGE</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> fetch_rss<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">12</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//3600 * 12 means 12 hours</span></pre></div></div>

<p>You can call the function with one (default) parameter and it&#8217;ll still work just fine albeit caching the feed to default cache age.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> fetch_rss<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//default cache age</span></pre></div></div>

<p>Hopefully it&#8217;ll help someone setting different <strong>cache ages</strong> for different RSS feeds in <strong>MagpieRSS</strong>.</p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/' rel='bookmark' title='Permanent Link: How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie'>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/' rel='bookmark' title='Permanent Link: Parsing News Feed using PHP &#038; MagpieRSS and making it scroll'>Parsing News Feed using PHP &#038; MagpieRSS and making it scroll</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
