<?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; RSS feeds</title>
	<atom:link href="http://www.parorrey.com/blog/tag/rss-feeds/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parorrey.com/blog</link>
	<description>random bits on web development</description>
	<lastBuildDate>Thu, 09 Sep 2010 10:45:49 +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>Parsing News Feed using PHP &amp; MagpieRSS and making it scroll</title>
		<link>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/</link>
		<comments>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 13:48:13 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[MagpieRSS]]></category>
		<category><![CDATA[News Scroller]]></category>
		<category><![CDATA[News Ticker]]></category>
		<category><![CDATA[RSS feeds]]></category>
		<category><![CDATA[RSS Parser]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=46</guid>
		<description><![CDATA[A while back I had to develop a news widget/ticker as part of my PHP website development project. First part was to fetch news items regularly via RSS feed, cache the feed and parse it for displaying and for this I used MagpieRSS. Second part was to show the parsed news items as scrolling text [...]


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>
<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>
</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%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>A while back I had to develop a news widget/ticker as part of my <a href="http://www.parorrey.com/" target="_blank">PHP website development</a> project.</p>
<p>First part was to fetch news items regularly via RSS feed, cache the feed and parse it for displaying and for this I used <a rel="nofollow" href="http://magpierss.sourceforge.net/" target="_blank">MagpieRSS</a>. Second part was to show the parsed news items as scrolling text or news ticker on a web page.</p>
<p>But first things first, check the demo of what we are talking about <a rel="nofollow" href="http://www.parorrey.com/test/news-ticker/" target="_blank">Demo MagpieRSS News Scroller</a>. </p>
<p>Here is the PHP code for fetching and parsing the news items using MagpieRSS.</p>
<p>First of all, include the Magpie class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>MAGPIE_DIR<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss_fetch.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//where MAGPIE_DIR is the path to magpie dir</span></pre></div></div>

<p>Provide the url and set number of items to be displayed (Ideally these should come from Database as I did in the said project managed via admin panel of CMS.):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/business/rss.xml'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//set  $num_of_items = 'All' to show all items;</span></pre></div></div>

<p>Now parse the feed and store all the data in the <strong>$rss_news_items</strong> variable to be displayed in the page later.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&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>
&nbsp;
  <span style="color: #000088;">$rss_feed_name</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">'Channel: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Updated: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastbuilddate'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num_of_items</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'All'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</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: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_of_items</span><span style="color: #009900;">&#41;</span>  <span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rss_news_items</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_of_items</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$href</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$rss_news_items</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&amp;nbsp;&amp;nbsp;&lt;span class=&quot;bgwithtext&quot;&gt;&lt;b&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/b&gt; - '</span><span style="color: #339933;">.</span><span style="color: #000088;">$date</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;&lt;span class=&quot;linkTextOnly&quot;&gt;&amp;nbsp;&lt;b&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</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;">$description</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&amp;nbsp;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now having parsed the RSS feed, we need to make news items scroll on page and for this I used this <a rel="nofollow" href="http://www.mioplanet.com/rsc/newsticker_javascript.htm" target="_blank">Scrolling News Ticker by Mioplanet</a>. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$rss_feed_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;
&lt;div id=&quot;TICKER&quot; STYLE=&quot;overflow:hidden; width:520px&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$rss_news_items</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;webticker_lib.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Don&#8217;t forget to place &#8220;webticker_lib.js&#8221; from <a rel="nofollow" href="http://www.mioplanet.com/rsc/newsticker_javascript.htm" target="_blank">Mioplanet</a> website in the same directory as your php page. You may also want to place following css class in your style sheet.</p>
<p>I selected Mioplanet js scroller due to its usefulness. You can set the ticker directon from left to right or otherwise, ticker speed and its styles easily.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.bgwithtext</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> orange<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I have put together a working php script with all the dependent files in this zipped folder <a rel="nofollow" href="http://www.parorrey.com/downloads/news-ticker.zip">Download PHP MagpieRSS News Scroller script</a>. Just make sure you have &#8216;/cache&#8217; directory at the root of your website and it is writable by php script (with chmod permissions 777).</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%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/feed/</wfw:commentRss>
		<slash:comments>2</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>
