<?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>DevRhino Inc.</title>
	<atom:link href="http://www.devrhino.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devrhino.com</link>
	<description>Outstanding Interactive Development in Los Angeles</description>
	<lastBuildDate>Wed, 13 Oct 2010 18:55:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Zend_Service_Flickr: Improving performance</title>
		<link>http://www.devrhino.com/2010/10/zend-service-flickr-performance/</link>
		<comments>http://www.devrhino.com/2010/10/zend-service-flickr-performance/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 18:53:03 +0000</pubDate>
		<dc:creator>rhino</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Kohana]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.devrhino.com/?p=43</guid>
		<description><![CDATA[I recently was working on a Flickr integration used in a promotional microsite for a certain major client. Kohana php framework is my weapon of choice in this situation for caching and serving all types of json-based web services and it works great for that but I needed some type of third-party library to use [...]]]></description>
			<content:encoded><![CDATA[<p>I recently was working on a Flickr integration used in a promotional microsite for a certain major client. Kohana php framework is my weapon of choice in this situation for caching and serving all types of json-based web services and it works great for that but I needed some type of third-party library to use for the actual Flickr part of things. I&#8217;ve used Zend a lot in the past and found their stuff works fairly well after a bit of tuning, so I decided on <a href="http://framework.zend.com/manual/en/zend.service.flickr.html" target="_blank">Zend_Service_Flickr</a> and went to work. This post deals with some stuff I did to the tagSearch() call to make things more efficient. I am also assuming that if you are reading this you are familiar with Zend Framework and are comfortable with extending classes from it.<br />
<span id="more-43"></span><br />
Basically the service is broken down into three main parts: the actual service class that builds, validates, and sends the queries; a ResultSet wrapper that takes in the XML returned by Flickr and parses it with DOMDocument and XPath; a Result wrapper that represents each node in the ResultSet &#8211; it acts as a VO class containing information about each photo returned from flickr.photos.search</p>
<p>What ends up happening is that the service makes a call to Flickr and passes the resulting XML into the ResultSet. ResultSet then loops through each node in it&#8217;s DOM tree and creates a new Result for each one. Then the Result VO makes a separate call to flickr.photos.getSizes for EACH IMAGE in the result set.</p>
<p>Making that many queries to the Flickr API (which is known to be slow anyway) just doesn&#8217;t fly in a production environment. Of course you cache all the results of the image sizes but even with that caching you are still doing WAY too many requests within too short of a time span for the API to keep up. Fortunately there is an easy fix for this.</p>
<p>currently in Zend_Service_Flickr_Result the offending part is this:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./@*'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$property</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$property</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$property</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_flickr <span style="color: #339933;">=</span> <span style="color: #000088;">$flickr</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_flickr<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getImageDetails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>getImageDetails() is a call in Zend_Service_Flickr that makes the external query to photos.getSizes. The thing is: this call is completely unnecessary because at this point <a target="_blank" href="http://www.flickr.com/services/api/misc.urls.html">you already have all the information you need to create all the image size urls </a>just from what photos.search returns.</p>
<p>What you can do is override and extend Zend_Service_Flickr_Result. Then replace the second foreach loop which calls getImageDetails (you still need the first foreach!). You can replace it with logic like this:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./@*'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$property</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$property</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$property</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://farm<span style="color: #006699; font-weight: bold;">{$this-&gt;farm}</span>.static.flickr.com/<span style="color: #006699; font-weight: bold;">{$this-&gt;server}</span>/<span style="color: #006699; font-weight: bold;">{$this-&gt;id}</span>_<span style="color: #006699; font-weight: bold;">{$this-&gt;secret}</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.flickr.com/photos/<span style="color: #006699; font-weight: bold;">{$this-&gt;owner}</span>/<span style="color: #006699; font-weight: bold;">{$this-&gt;id}</span>/sizes/&quot;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://farm<span style="color: #006699; font-weight: bold;">{$this-&gt;farm}</span>.static.flickr.com/<span style="color: #006699; font-weight: bold;">{$this-&gt;server}</span>/<span style="color: #006699; font-weight: bold;">{$this-&gt;id}</span>_<span style="color: #006699; font-weight: bold;">{$this-&gt;secret}</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.flickr.com/photos/<span style="color: #006699; font-weight: bold;">{$this-&gt;owner}</span>/<span style="color: #006699; font-weight: bold;">{$this-&gt;id}</span>/sizes/&quot;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Square'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'uri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_s.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'clickUri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'sq/'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Thumbnail'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'uri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_t.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'clickUri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'t/'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Small'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'uri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_m.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'clickUri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'s/'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Medium'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'uri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'clickUri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'m/'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Large'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'uri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseUri</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_b.jpg'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'clickUri'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$baseClick</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'l/'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Now you have an array called $image which contains all of the image links (i.e. all of the information that flickr.photos.getSizes returns), without having to make an extra call.</p>
<p>To integrate this with Zend_Service_Flickr you will need to extend FlickrResultSet->current() so that it uses your new Result class like so:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <a href="http://www.php.net/current"><span style="color: #990000;">current</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> &nbsp;My_Service_Flickr_Result<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_results<span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_currentIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_flickr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>And you will also have to override Zend_Service_Flickr->tagSearch() so that it will use your new ResultSet class instead of the default. Just change the last line of the function to</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> My_Service_Flickr_ResultSet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dom</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I know all that might look confusing but if you have used Zend Framework before you know that this is just how it goes <img src='http://www.devrhino.com/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Anyway, I hope you find this useful. Happy Flickr-ing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devrhino.com/2010/10/zend-service-flickr-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Code Highlight</title>
		<link>http://www.devrhino.com/2010/10/testing-code-highlight/</link>
		<comments>http://www.devrhino.com/2010/10/testing-code-highlight/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 18:03:02 +0000</pubDate>
		<dc:creator>rhino</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://new.devrhino.com/?p=16</guid>
		<description><![CDATA[I just installed a new code and syntax highlight plugin: CodeColorer by kpumuk. What do you think? &#60;?php echo &#34;hello world!&#34;; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>I just installed a new code and syntax highlight plugin: <a  target="_blank" href="http://wordpress.org/extend/plugins/codecolorer/">CodeColorer</a> by kpumuk. What do you think?</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hello world!&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.devrhino.com/2010/10/testing-code-highlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://www.devrhino.com/2010/10/hello-world/</link>
		<comments>http://www.devrhino.com/2010/10/hello-world/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 05:21:41 +0000</pubDate>
		<dc:creator>rhino</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://new.devrhino.com/wp/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!]]></description>
			<content:encoded><![CDATA[<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devrhino.com/2010/10/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

