<?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>mikhail panchenko / blog &#187; php</title>
	<atom:link href="http://mihasya.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mihasya.com/blog</link>
	<description>good things now come in packages of three</description>
	<lastBuildDate>Thu, 22 Mar 2012 21:08:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Define Failure&#8230;</title>
		<link>http://mihasya.com/blog/define-failure/</link>
		<comments>http://mihasya.com/blog/define-failure/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 21:55:07 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[memcache]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=172</guid>
		<description><![CDATA[Just saw a salient example of something I notice quite a bit in various documentation sources. Lots of manuals and API references will say stuff like &#8220;Returns FALSE on failure&#8221; with little to no clarification as to what that means. Though it is usually intuitive, there are frequent cases where a little more attention should [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-173" title="failure graphic" src="http://mihasya.com/blog/wp-content/uploads/2008/12/cubs-failure-1.jpg" alt="failure graphic" width="368" height="343" />Just saw a salient example of something I notice quite a bit in various documentation sources.</p>

<p>Lots of manuals and API references will say stuff like &#8220;Returns FALSE on failure&#8221; with little to no clarification as to what that means. Though it is usually intuitive, there are frequent cases where a little more attention should be paid. Example: PHP manual page for Memcache::delete.</p>

<p>The method takes two parameters: the key to be deleted and the optional timeout. The second parameter specifies how long Memcache should wait before deleting the key. Like many others, the function &#8220;Returns TRUE on success or FALSE on failure.&#8221;</p>

<p>The primary use case of this method is obviously just deleting a value stored in memcached. But let&#8217;s actually examine the possible outcomes.</p>

<ul>
    <li>Key is found and successfully deleted. Obvious Success.</li>
    <li>Memcached server cannot be reached. Obvious Failure.</li>
    <li>Key is found, but some sort of network or server glitch prevents it from being deleted. Obvious Failure.</li>
    <li>Key doesn&#8217;t exist. How do we classify this? On one hand, the &#8220;goal&#8221; of calling the method is accomplished &#8211; the key is not in Memcache. However, the method itself didn&#8217;t technically do what it was supposed to do. Its purpose is to delete a key, and it didn&#8217;t. Furthermore, it appears that the developer was mistaken as to the state of the cache. Though in a lot of cases that&#8217;s fine, what if the developer is privately counting on the key actually being there (this will be more fleshed out in the second usecase). Matters are further complicated by things like memcachedb &#8211; a persistent storage backend that uses the memcache protocol. Here, a missing key could present a serious problem, and the developer should definitely know about it, granted this could just be another argument against putting persistent storage behind a protocol meant for the opposite. One way or another, it&#8217;s not clear from the documentation what the method would return in this event.</li>
</ul>

<p>Things get a little more complicated once the second parameter is invoked. The timeout parameter allows the developer to delay the deletion of the key. The first three bullets above roughly apply the same way with minor obvious adjustments (i.e, in the third bullet replace &#8220;being deleted&#8221; with &#8220;having its ttl adjusted&#8221;).</p>

<p>The fourth bullet, however, is even more salient. The setting of a timeout value implies that the developer indeed not only expects the key to be there, but is counting on the key to be there n seconds later.</p>

<p>Naturally, I fully understand that one should rarely COUNT on certain things being in the cache, so the aforementioned concerns will likely be irrelevant in most applications. However, I&#8217;m not singling out PHP or Memcache: the same concern applies to plenty of other APIs. I remember wondering what &#8220;Failure&#8221; meant to the YUI Get utility (I thought it was just a non-200 HTTP code, but directing it to a non-existent URL didn&#8217;t seem to trigger it, so it&#8217;s unclear), and there are plenty of other cases.</p>

<p>I&#8217;m not a fan of returning error codes and having to use huge switch statements to determine what to do in the event of every failure in the application, nor do I advocate throwing finegrained exceptions left and right (the two are nearly identical in my mind). However, I do believe that more care should be taken to document what constitutes a failure and, for functions that don&#8217;t have a clearly defined return value, success. Perhaps @failure and @success tags can be added to the docblock spec to facilitate such documentation. For every place in a method where false is returned to signify failure, a @failure block would be added, and likewise for success.</p>

<p>PS: if anybody happens to know the correct answer to my Memcache::delete question, let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/define-failure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Couple of Quick PHP Tricks</title>
		<link>http://mihasya.com/blog/a-couple-of-quick-php-tricks/</link>
		<comments>http://mihasya.com/blog/a-couple-of-quick-php-tricks/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 18:33:27 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array_keys]]></category>
		<category><![CDATA[array_splice]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=164</guid>
		<description><![CDATA[More seasoned PHP hackers probably already know this stuff, but I thought I&#8217;d share a couple things that made me think &#8220;Man this is a cool fucking feature&#8221; when I used them in my work yesterday. array_keys is smarter than it looks The short description for this function in the PHP docs says &#8220;array_keys — [...]]]></description>
			<content:encoded><![CDATA[<p>More seasoned PHP hackers probably already know this stuff, but I thought I&#8217;d share a couple things that made me think &#8220;Man this is a cool fucking feature&#8221; when I used them in my work yesterday.</p>

<h3>array_keys is smarter than it looks</h3>

<p class="refpurpose">The short description for this function in the PHP docs says &#8220;<span class="refname">array_keys</span> — <span class="dc-title">Return all the keys of an array.&#8221; Unfortunately, that is as far as a lot of people read. However, there is an incredibly useful feature hidden in the optional parameters: &#8220;</span>If the optional <em><tt class="parameter">search_value</tt></em> is specified,    then only the keys for that value are returned.&#8221; So apart from just dumbly getting all the keys the array contains, you can actually parse out some really useful stuff.</p>

<p class="refpurpose"><strong>Use Case:</strong></p>

<p class="refpurpose">You have a table that lists a bunch of entities, and you have to give the user the ability to perform n actions where n &gt; 1 and the actions are mutually exclusive. Simply defining a bunch of checkbox arrays won&#8217;t work, so you have to use radio buttons. (You could use checkboxes and use javascript to ensure the exclusivity, but then you&#8217;d be a jackass).</p>

<p class="refpurpose">Radio buttons, as you know, group by name. So you have to have N radio buttons per row, each with a different value, and a name that indicates which entity the input pertains to. If you&#8217;re really smart, you could make each radio group a member of an array, where the array&#8217;s key indicates the ID of the entity:</p>

<p><pre class="refpurpose">&lt;input type="radio" name="action[&lt;?= $entity-&gt;id ?&gt;]" value="delete" /&gt;</pre></p>

<p class="refpurpose">When the form is submitted, you&#8217;ll end up with $_POST['action'][12] =&gt; &#8216;delete&#8217;, etc.</p>

<p class="refpurpose">Now that you&#8217;ve got your input in a nice, tidy array, you can start the magic:</p>

<p><pre class="refpurpose">$deletions = array_keys($_POST['action'], 'delete');
$approvals = array_keys($_POST['action'], 'approve');</pre></p>

<p class="refpurpose">Now you have just the ID&#8217;s of the entities that need to be deleted or approved. Unless you have some really shitty logic libraries, that should make yoru life incredibly easy. I obviously skipped stuff like validation for the sake of brevity and readability, but I would also recommend mapping your actions to an indexed array, so that your radio value were actually more like 0, 1, 2, 3, etc so as to minimize the amount of data posted. Some would also say that you shouldn&#8217;t use PHP short tags, but I really just don&#8217;t care.</p>

<p class="refpurpose">I should also mention that in PHP 5 array_keys has a third parameter bool $strict, which causes it to use === comparison instead of == when parsing the array. Full manual <a title="array_keys php manual page" href="http://us.php.net/manual/en/function.array-keys.php" target="_blank">here</a>.</p>

<h3 class="refpurpose">array_splice&#8217;s 4th optional parameter might be its most useful</h3>

<p class="refpurpose">I found myself somewhat dumbfounded when a co-worker asked me if there was a standard function in PHP to insert a set of values at a given point inside an indexed array &#8211; I couldn&#8217;t think of it! My intuition drew me towards array_splice, even though I knew that the default behavior of that function was the opposite. Having just used the aforementioned obscure feature of array_keys, I guessed that array_splice would either have a similar feature or would direct me to the manual page for its compliment function. The former was correct.</p>

<p class="refpurpose">The 4th parameter of array_splice is $replacement. It is pretty self explanatory, but I&#8217;ll hold your hand like a small child and do an example anyway.</p>

<p><pre class="refpurpose">&lt;?php
$alphabet = $alphabet_broken = range('a','z');
//default behavior. We just got rid of b and c
$missing = array_splice($alphabet_broken, 1, 2);
//same offset, 0 length so nothing is removed
//the missing letters in $replacemenent
array_splice($alphabet_broken, 1, 0, $missing);
//if I don't suck at life, the two should be identical
if (array_diff($alphabet, $alphabet_broken)) {
    echo "Something got fucked up!";
}
?&gt;</pre></p>

<p class="refpurpose">The full manual entry for array_splice is <a title="PHP manual page for array_splice" href="http://us.php.net/manual/en/function.array-splice.php" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/a-couple-of-quick-php-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My C is more better now!</title>
		<link>http://mihasya.com/blog/my-c-is-more-better-now/</link>
		<comments>http://mihasya.com/blog/my-c-is-more-better-now/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 00:10:30 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=158</guid>
		<description><![CDATA[I have pushed an update for my silly php extension to github for anyone that wants to have a looksie. I&#8217;ve optimized the human_interval_precise function to only declare two variables (the long to hold the number of seconds passed in from userspace and the char array that gets passed back). Still need to figure out [...]]]></description>
			<content:encoded><![CDATA[<p>I have pushed an update for my silly php extension to github for anyone that wants to have a <a title="human.c on github" href="http://github.com/mihasya/human/tree/master/human.c">looksie</a>. I&#8217;ve optimized the human_interval_precise function to only declare two variables (the long to hold the number of seconds passed in from userspace and the char array that gets passed back). Still need to figure out a sensible max length for the return value and replace the arbitrary char[60] I have in there now.</p>

<p>I&#8217;ve also added a human_interval (not precise) function for approximating in the largest possible units. However, I just realized as I was writing this that I forgot to make it round in any way, so it probably comes up with fairly bogus results right now. Fail. Good thing this is just an exercise, and I&#8217;ll have another 3 hours on a shuttle to kill on Monday&#8230; and on Tuesday&#8230; and on Wednesday&#8230;</p>

<p>As I said before, I&#8217;m also working on a redo of the WordPress theme, as well as another more &#8220;grown up&#8221; C project.</p>

<p>Also, did not get laid off. Best of luck to all that did. Crazy times we live in.</p>

<p>PS: just saw on my nifty little wordpress toolbar that 2.7 is available. FUCKING ROCK! New design coming with the quickness.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/my-c-is-more-better-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning to walk after running for 4 years: from PHP to C</title>
		<link>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/</link>
		<comments>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 20:05:48 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[c php extension]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=147</guid>
		<description><![CDATA[In an effort to stop being such a fucking noob, I&#8217;ve seriously taken up C. As a natural transition/crutch, I have started with PHP extensions. The PHP API basically picks your droppings up after you with a plastic bag, so it&#8217;s pretty easy. Using ext_skel gave me pretty much everything I needed, since I&#8217;ve only [...]]]></description>
			<content:encoded><![CDATA[<p>In an effort to stop being such a fucking noob, I&#8217;ve seriously taken up C. As a natural transition/crutch, I have started with PHP extensions. The PHP API basically picks your droppings up after you with a plastic bag, so it&#8217;s pretty easy. Using ext_skel gave me pretty much everything I needed, since I&#8217;ve only written one function so far and have not done anything fancy.</p>

<p>The extension is called &#8220;human,&#8221; short for &#8220;human readable.&#8221; The first function, human_interval_precise, simply represents a number of seconds in the largest &#8220;precise&#8221; time units possible. That is, thousands of seconds are converted to weeks, days, hours, minutes, and seconds as needed. The source is <a title="human git tree" href="http://github.com/mihasya/human/tree/master">here</a>.</p>

<h3>Lessons</h3>

<p>I&#8217;m obviously still a giant noob, but there are some things that I have picked up along the way (mostly via <a title="crowley's blog" href="http://rcrowley.org/">Crowley</a>) that made things a lot clearer. Hopefully my posting this will help other noobs following in my footsteps.</p>

<h4>&#8220;Pointers are just numbers&#8221;</h4>

<p>Yup. Just the number of memory blocks from the start of the segment of memory you&#8217;re dealing with. &#8220;Pointer math&#8221; is really just math: p+5 really is just the position in memory 5 blocks away from the start of p. The size of the blocks is determined by the pointer type, so if you have a char pointer, the blocks are 1 byte.</p>

<h4>an array is just a pointer to a set of consecutive memory blocks</h4>

<p>The name of the array is just the pointer to the first element. This is particularly important with char arrays. When I do the following in my code, I am just adding output to the end of an already existing &#8220;string.&#8221;
<pre><span class="n">sprintf</span><span class="p">(</span><span class="n">retstr</span><span class="o">+</span><span class="n">strlen</span><span class="p">(</span><span class="n">retstr</span><span class="p">),</span> <span class="s">"%dd "</span><span class="p">,</span> <span class="n">days</span>);</pre>
The K&amp;R section on the relationship between arrays and pointers is incredibly useful.</p>

<h4>Always remember to initialize your strings</h4>

<p>Nothing says &#8220;FAIL&#8221; like running your PHP function more than once in the same script and seeing it return its result appended to the end of the result from the previous call. A simple
<pre>*retstr = 0;</pre>
at the top of the function takes care of the problem. Otherwise, your char pointer ends up pointing to memory that isn&#8217;t claimed by anything else, but isn&#8217;t cleared either. In the case of consecutive PHP function runs, it just happens to be the previous output. It could end up being any sort of useless garbage.</p>

<p>I started writing this entry a few weeks ago and got sidetracked by a bigger and more interesting project/thanksgiving. As a result, I don&#8217;t remember what else I was going to write, so I&#8217;ll just wrap it up. More C learnings coming soon. It has been a humbling experience to say the least.</p>

<address></address>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>i&#8217;m branching out: c, python, maybe even java&#8230;</title>
		<link>http://mihasya.com/blog/im-branching-out-c-python-maybe-even-java/</link>
		<comments>http://mihasya.com/blog/im-branching-out-c-python-maybe-even-java/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 00:16:30 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=66</guid>
		<description><![CDATA[Though I had made my mind up a while ago to start seriously hacking other languages besides PHP, I saw something today that really reinforced that decision: average programmer salaries. Erlang $99,000 (added 8 June 2008) &#8230; Java $79,000 Python $78,000 Perl $77,000 Ruby $74,000 COBOL $73,000 (added due to demand) JavaScript $72,000 ColdFusion $64,000 [...]]]></description>
			<content:encoded><![CDATA[<p>Though I had made my mind up a while ago to start seriously hacking other languages besides PHP, I saw something today that really reinforced that decision: <a href="http://theunixgeek.blogspot.com/2008/06/programming-salaries.html">average programmer salaries</a>.</p>

<blockquote>
<div>Erlang $99,000 (added 8 June 2008)
&#8230;
Java $79,000
Python $78,000
Perl $77,000
Ruby $74,000
COBOL $73,000 (added due to demand)</div>
<div>JavaScript $72,000</div>
<div>ColdFusion $64,000 (8 June 2008)</div>
<div>Delphi $64,000
PHP $64,000
&#8230;</div></blockquote>

<p>Yikes!</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/im-branching-out-c-python-maybe-even-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>where the eff have i been?</title>
		<link>http://mihasya.com/blog/where-the-eff-have-i-been/</link>
		<comments>http://mihasya.com/blog/where-the-eff-have-i-been/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 02:31:43 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysql2008]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=54</guid>
		<description><![CDATA[As I&#8217;ve previously mentioned, I am at MySQL 2008 in Santa Clara. I&#8217;ve been busy going to the talks, hanging out, and soaking in the weather. Coding wise, I&#8217;ve been at a standstill &#8211; I had to do a bunch of stuff for work, came up with a mess of ideas that I had to [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve previously mentioned, I am at MySQL 2008 in Santa Clara. I&#8217;ve been busy going to the talks, hanging out, and soaking in the weather.</p>

<p>Coding wise, I&#8217;ve been at a standstill &#8211; I had to do a bunch of stuff for work, came up with a mess of ideas that I had to filter and decide what I actually wanted to work on, and then realized I didn&#8217;t want to start working on anything else until I finished ked_duffel, or at least got it to be usable. That itself became a bottleneck as I struggled to figure out how to handle variables within files, but I&#8217;ve come up with what I think is a relatively elegant, cheap, and maintainable solution, so I&#8217;ve started development. I&#8217;ll post details as I implement the stuff</p>

<h3>The Conference</h3>

<p>I have learned quite a bit of stuff. As I work at a place where we don&#8217;t have dedicated DBA&#8217;s, but are getting to the point where at least minimal optimization and scaling are becoming a necessity, it was great to hear some talks about efficient scaling, caching, and proper monitoring/query analysis and optimization. Of particular interest and use were the memcached talk and the various discussions of stored procedures. Though only useful in the future (it&#8217;ll be a while before MySQL 5.1 is available to us), partitioning also seems like something that would help us out a great deal.</p>

<p>All in all, I&#8217;m getting my (read: Yahoo&#8217;s) money&#8217;s worth and having a good time. I have generated lots of ideas on how we can drastically ameliorate a lot of our performance issues and make our database much more maintainable.</p>

<p>One thing that kind of sucks is that a lot of the talks about monitoring/alerting ended up a waste, as they talked about opensource products that we had looked at and ended up developing our own due to scale issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/where-the-eff-have-i-been/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>oEmbed, or what I did instead of reading for class</title>
		<link>http://mihasya.com/blog/oembed-or-what-i-did-instead-of-reading-for-class/</link>
		<comments>http://mihasya.com/blog/oembed-or-what-i-did-instead-of-reading-for-class/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 05:40:29 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=46</guid>
		<description><![CDATA[Like I said, I was writing a wordpress plugin. I wanted to automatically highlight code posted within &#60;pre&#62; tags. And no, I didn&#8217;t want &#60;code&#62; tags b/c those aren&#8217;t part of the native wordpress editor toolbar &#8211; the goal was to be able to embed highlighted code while just being completely lazy and staying the [...]]]></description>
			<content:encoded><![CDATA[<p>Like I said, I was writing a wordpress plugin. I wanted to automatically highlight code posted within &lt;pre&gt; tags. And no, I didn&#8217;t want &lt;code&gt; tags b/c those aren&#8217;t part of the native wordpress editor toolbar &#8211; the goal was to be able to embed highlighted code while just being completely lazy and staying the &#8220;Visual&#8221; tab.</p>

<p>This got boring really quickly, especially once I saw that someone had already done something similar, except <a href="http://www.nextthing.org/code/wp-states-highlight/">weak and pointless</a>. If I&#8217;m going to upload &#8220;code snippets,&#8221; why don&#8217;t I just run them through enscript while I&#8217;m at it and paste the damn output?</p>

<p>Anyway, then I thought &#8220;Hey, this <a href="http://tantannoodles.com/toolkit/wp-flickr-post-bar/">flickr plugin</a> I&#8217;m using kinda sucks and isn&#8217;t very good about letting me pick which size of photo I want to embed.&#8221; It&#8217;s a global setting. FAIL.</p>

<p>So then I thought &#8220;If Crowley&#8217;s drunken ramblings about some sort of open standard for embedding media had any actual substance, I could easily improve this.&#8221;</p>

<p>They did. He was talking about <a href="http://oembed.com/">oEmbed</a>.</p>

<p>I&#8217;m gonna cut this story short because I&#8217;m fucking burned, but here&#8217;s what I posted on Cal Henderson&#8217;s <a href="http://www.iamcal.com/discuss/topic7158/#reply141462">website&#8217;s discussion</a>:</p>

<blockquote>I&#8217;m messing around with oembed on flickr &#8211; not seeing a way to specify which size of the image I want to embed. I tried some combinations of changing the URL and maxwidth/maxheight settings in the request, but to no avail.

I tried:
<a href="http://www.flickr.com/services/oembed/?url=http://flickr.com/photos/mikepanchenko/617998417/&amp;maxwidth=3000&amp;maxheight=2000">www.flickr.com/services/oem&#8230;</a>
<a href="http://www.flickr.com/services/oembed/?url=http://flickr.com/photos/mikepanchenko/617998417/sizes/o/">www.flickr.com/services/oem&#8230;</a>
<a href="http://www.flickr.com/services/oembed/?url=http://flickr.com/photos/mikepanchenko/617998417/sizes/o/&amp;maxwidth=3000&amp;maxheight=2000">www.flickr.com/services/oem&#8230;</a>

All three return the same thing:
[ the xml output of <a href="http://www.flickr.com/services/oembed/?url=http://flickr.com/photos/mikepanchenko/617998417/">this request</a> ]
Are we not there yet?

I was thinking of making a flickr oembed wordpress plugin. It&#8217;ll still work, but will be limited to the one size.

Is there a way to work this? Would it be possible to set up server side logic @flickr which actually checks the <strong>/sizes/foo</strong> part of the URL and returns the appropriate URL/size info? I haven&#8217;t thought about it long (and it&#8217;s late) but that seems to be in line with the standard &#8211; would only have to change the url GET var in the request, putting all the logic on the providers side and just spitting out the right image.

Cheers.

Mike.</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/oembed-or-what-i-did-instead-of-reading-for-class/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Project ADD</title>
		<link>http://mihasya.com/blog/project-add/</link>
		<comments>http://mihasya.com/blog/project-add/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 03:59:42 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ked]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=42</guid>
		<description><![CDATA[Just had another &#8220;AWESOME&#8221; idea today that fits nicely with my desire to create something that can stay with an app as it grows. Once ked_core functionality is more or less finalized (sooner rather than later), I&#8217;m going to start hacking up a pecl extension that will mimic ked_core&#8217;s behavior perfectly, thus allowing the developer [...]]]></description>
			<content:encoded><![CDATA[<p>Just had another &#8220;AWESOME&#8221; idea today that fits nicely with my desire to create something that can stay with an app as it grows. Once <strong>ked_core</strong> functionality is more or less finalized (sooner rather than later), I&#8217;m going to start hacking up a <strong>pecl extension</strong> that will mimic ked_core&#8217;s behavior perfectly, thus allowing the developer to simply comment out the <strong>require_once</strong> statement in <strong>index.php</strong> having installed the extension, maintaining the exact same behavior, but with less overhead, since the framework&#8217;s core will now be compiled.</p>

<p>As Crowley put it, that is overkill. I know. But I need to learn how to write PHP extensions <img src='http://mihasya.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p>I realize that I&#8217;ve started more projects in the last month than I have in the last 2 years. I am going to prioritize things a little bit &#8211; I want to focus on <strong>ked_duffel</strong> (the SVN delivery system) to start out, then once that&#8217;s functional use it to update mihasya.com&#8217;s framework files, then tinker with the framework a little bit, using duffel to test it on mihasya.com.</p>

<p>Once I&#8217;m happy with its functionality, I&#8217;ll start compiling a pecl skeleton and trying to fill it out, making heavy use of my rollover minutes &#8211; to call <a href="http://rcrowley.org">Crowley</a> with dumb C questions.</p>

<p>Of course, all of this is going to have to wait a little bit &#8211; I realized recently that nearly two weeks had passed without me having done any paid work. Someone has to pay for Crowley&#8217;s lapdances, so I am going to dedicate a bit more time to Yahoo! stuff in the coming couple of weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/project-add/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionless Views: The Quest For Perfection</title>
		<link>http://mihasya.com/blog/actionless-views-the-quest-for-perfection/</link>
		<comments>http://mihasya.com/blog/actionless-views-the-quest-for-perfection/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 06:33:20 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ked]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=39</guid>
		<description><![CDATA[The idea here is being able to route ked_core to a static template w/o executing any action or having defined one. For example, if you want your header to just be static HTML and want that in a separate header.tpl file, there&#8217;s no reason you should have to define controller-&#62;header() just to access that. I [...]]]></description>
			<content:encoded><![CDATA[<p>The idea here is being able to route ked_core to a static template w/o executing any action or having defined one. For example, if you want your header to just be static HTML and want that in a separate <strong>header.tpl</strong> file, there&#8217;s no reason you should have to define <strong>controller-&gt;header()</strong> just to access that.</p>

<p>I went through several iterations on this code (some of it is in svn, though not all &#8211; I had to start the repository over b/c I forgot to add trunk/ branches/ and tags/ <img src='http://mihasya.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ) so here is my approximate thought process.</p>

<h4>Step 1: Check the .tpl exists</h4>

<p>I should have had this check anyway, but before I did not realize the need &#8211; there needed to be an action defined for the view to be rendered anyway, so I focused on that, and that seemed to take care of itself. The following line would just throw an Exception
<pre>$reflector = new ReflectionMethod($this, $action);</pre>
which would then just be handled and displayed nicely with ked&#8217;s exception handler.</p>

<p>But now I really do need to actually handle this on its own, since the action might not even exist &#8211; WHAT WILLS WAE DO THARN?!</p>

<p><strong>The Wrong Way:</strong>
<pre>if (ked::$smarty-&gt;template_exists($tpl)) { ...</pre>
No. That is clearly a file system operation that will be run every single time, even though we know that 99% of the time, unless the developer is a total and complete dunce, the template is there. Then there&#8217;s the additional fs read to load the template.</p>

<p><strong>The Right Way:</strong></p>

<p>The right way looks sort of hackish, but bear with me. Smarty is really dumb about how $smarty-&gt;display() works. It never returns anything. If it fails to load the template, it prints a warning. Can&#8217;t really check to see if it succeeded in any robust way, so this will do:
<pre>...
ob_start();
ked::$smarty-&gt;display($tpl);
$viewContent = ob_get_contents();
ob_end_clean();
if (!$this-&gt;_skipAssign) ked::$smarty-&gt;clear_all_assign();
if (strpos($viewContent, "&lt;b&gt;Warning&lt;/b&gt;:  Smarty error: unable to read resource:")!==false)
  throw new kedException('The view "'.$this-&gt;_view.'" was not found')
...</pre>
I just check for the presence of the warning and throw an exception if it&#8217;s there. Now, normally, I am not a fan of throwing exceptions, but in this spot it&#8217;s ok, and I&#8217;ll explain later why. The short explanation: because we&#8217;re not catching it.</p>

<h4>Step 2: Make _execute Not Choke On Absent Action</h4>

<p><strong>The Wrong Way:</strong></p>

<p>This is where I originally threw an exception, but a comment by <a href="http://cowsandmilk.net/">David Hall</a> made me pause.
<pre>...
try {
  $reflector = new ReflectionMethod($this, $action);
} catch (Exception $e) {
  $this-&gt;_skipAssign = true; //tell _render to skip smarty-&gt;assign related steps for this.
  return false;
}
...</pre>
So here, we just try to create a <a href="http://us.php.net/reflection">ReflectionMethod</a> as we normally would for the action, but if we see an exception, we just return; out of _execute and go on to _render. It&#8217;s sort of sloppy (because what if ReflectionMethod&#8217;s __construct() threw an exception for some other reason) and the real problem is this: we are creating and catching an exception in framework code. Every time an actionless view is called, this will happen. David pointed out that the exception is itself an object and can be quite heavy.</p>

<p><strong>The Right Way:</strong></p>

<p>This caused me to revert to my original intuition for how to do this:
<pre>...
if (!method_exists($this, $action)) {
  $this-&gt;_skipAssign = true; //tell _render to skip smarty-&gt;assign related steps for this.
  return false;
}
...</pre>
We just check if the method exists; if not, we set a variable that tells _render to forego assigning template variables that would have been set in the action had it existed and return false. (Right now, just returning would suffice, but I feel a disturbance in the force that tells me that this false value will come in handy somewhere down the line).</p>

<h4>Step 3 (bonus): Make _render More Efficient</h4>

<p>I alluded to this in an earlier code snippet: now that we can know for sure if an action has been executed, we can do this:
<pre>...
ob_start();
ked::$smarty-&gt;display($tpl);
$viewContent = ob_get_contents();
ob_end_clean();
if (!$this-&gt;_skipAssign) ked::$smarty-&gt;clear_all_assign();
if (strpos($viewContent, "&lt;b&gt;Warning&lt;/b&gt;:  Smarty error: unable to read resource:")!==false)
  throw new kedException('The view "'.$this-&gt;_view.'" was not found');
$this-&gt;viewContent = $viewContent;
$this-&gt;_skipAssign = false; //reset this to make sure subsequent actions don't get tainted
...</pre>
We check the bool we set earlier and forego template var assignment if it&#8217;s set to true. Once again, the exception is fine because we&#8217;re not catching it, and this is meant for exceptional cases that are supposed to grind our application to a halt. Unlike the case in _execute, this wont&#8217; be called every time there&#8217;s an actionless view &#8211; just in the case of an error.</p>

<h4>What Did We Gain From All This?</h4>

<p>Well, I listened to a bunch of really fucking good music on my ipod while doing this, so that&#8217;s good enough for me. But seriously, I also ordered like 6 <a href="http://www.threadless.com">Threadless</a> shirts.</p>

<p>Also, as a side benefit, the framework now supports actionless views without any extra file system operations. It is also wise enough not to bother assigning template variables if the template is static. You also don&#8217;t have to define anything special in the controller (in fact, nothing at all is needed there) or in the template to accomplish it &#8211; just put the static .tpl file in the right folder under inc/tpl/views.</p>

<p>I also used the word &#8220;tainted&#8221; in the comments&#8230; which is pretty close to &#8220;taint&#8221;&#8230; which is the area between the ass and the balls. That&#8217;s a wrap on the day.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/actionless-views-the-quest-for-perfection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>So What Happened Last Night?</title>
		<link>http://mihasya.com/blog/so-what-happened-last-night/</link>
		<comments>http://mihasya.com/blog/so-what-happened-last-night/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 15:38:59 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ked]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=37</guid>
		<description><![CDATA[Fail, that&#8217;s what happened. A big fat sack of fail. So as I was working on mihasya.com, I was simultaneously tinkering with ked_core &#8211; a natural thing to happen, since mihasya.com is a test for how ked_core actually does when used in practice (it kicks ass, fyi). I got the idea to permit actionless views [...]]]></description>
			<content:encoded><![CDATA[<h4>Fail, that&#8217;s what happened. A big fat sack of fail.</h4>

<p>So as I was working on <strong>mihasya.com</strong>, I was simultaneously tinkering with <strong>ked_core</strong> &#8211; a natural thing to happen, since <strong>mihasya.com</strong> is a test for how <strong>ked_core</strong> actually does when used in practice <strong>(it kicks ass, fyi)</strong>. I got the idea to permit actionless views (more on how, once again, I did that better than you later), so I got all excited and immediately hacked up the code. So now I had this code that was directly applicable to <strong>mihasya.com</strong> (a lot of the inner pages don&#8217;t do much, so don&#8217;t need a controller function defined) in the <a href="http://svn.mihasya.com/ked_core">ked_core svn</a>, but not on the site.</p>

<p><strong>The problem is</strong>: now that ked just ships as a big hunk of folders with the internal files and the site&#8217;s own files mixed in, the separation gets tricky. Also, my blog/ folder (the WordPress install) had to go under <strong>mihasya.ked/www/blog</strong>, as that was what my <strong>mihasya.com</strong> folder was symlinked to&#8230; Long story short, I straight up deleted <strong>mihasya.ked</strong>. That was fine, I thought, because I still had all that code in svn&#8230;.  OOOOPS. Thank goodness for database storage.</p>

<h4>Where This Leaves an Ambitious Mother F@#$%#</h4>

<p>Well, this is a problem I gots ta solve. It&#8217;s plagued me for years, as applications come shipped in huge tarballs that just extract like they&#8217;re kings of the world. If you want to selectively update something, you have to cp files one at a time. Fuck that.</p>

<p>How do I elegantly, and from within the framework, permit the developer to upgrade ked files, but not affect his own? This could be solved easily by some sort of package manager like apt or rpm, but we don&#8217;t have that luxury. Or rather, I won&#8217;t give myself that luxury. This will be solved with bash, php, and svn in the spirit of minimalistic requirements. After all, it has to work on Dreamhost <img src='http://mihasya.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<h4>What I Intend To Do</h4>

<p>This is how it&#8217;s goin down, homegirls: I am going to write a shell script which will fetch a special file from a predetermined svn location (the repository doesn&#8217;t have to be static, as I&#8217;m sure ked will have thousands of mirrors as it sweeps the market <img src='http://mihasya.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) The file will contain a listing of files which are internal to ked. It will probably just look something like this:
<pre>...
inc/controllers/internal
inc/core
inc/tpl/layouts/internal
...</pre>
The script will check the internal files on the repository for updates (including a self-update), download them to a separate copy (to avoid messing up your own .svn folders, if any are present) and copy them into your own dev tree.</p>

<p>One problem I&#8217;m already seeing before I even start hacking this up is that <strong>www/index.php</strong> contains configuration information that I refuse to move into a conf file (extra file read) that might get overwritten in this way, but I can probably figure out a way to handle that without quite developing a full blown package manager variable manipulation deal. Or maybe I&#8217;ll just do that. Cuz I can, son!</p>

<p>Stay tuned for more on this and other ked shenanigans.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/so-what-happened-last-night/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

