<?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>WarpConduit.Net</title>
	<atom:link href="http://www.warpconduit.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.warpconduit.net</link>
	<description>Intergalactic Brain Food</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:35:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Enable PHP 5.3 on HostMonster Shared Web Hosting</title>
		<link>http://www.warpconduit.net/2012/01/27/how-to-enable-php-5-3-on-hostmonster-shared-web-hosting/</link>
		<comments>http://www.warpconduit.net/2012/01/27/how-to-enable-php-5-3-on-hostmonster-shared-web-hosting/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 03:37:52 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=417</guid>
		<description><![CDATA[You heard it right, you can now run PHP 5.3 applications on HostMonster. I&#8217;ve only testing this on HostMonster, but I would assume the same applies to BlueHost. Simply add this line to the beginning of your website&#8217;s root .htaccess file: AddHandler application/x-httpd-php53 .php After making this change you can test it using phpinfo() and [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_423" class="wp-caption alignright" style="width: 160px"><a title="Hostmonster phpinfo output" href="http://www.warpconduit.net/wp-content/uploads/hostmonster-phpinfo-01272012.pdf" target="_blank"><img class="size-thumbnail wp-image-423" title="phpinfo" src="http://www.warpconduit.net/wp-content/uploads/phpinfo-150x150.jpg" alt="phpinfo" width="150" height="150" /></a><p class="wp-caption-text">Click image to view full phpinfo() output PDF</p></div>
<p>You heard it right, you can now run PHP 5.3 applications on <a href="http://www.hostmonster.com" target="_blank">HostMonster</a>. I&#8217;ve only testing this on HostMonster, but I would assume the same applies to BlueHost.</p>
<p>Simply add this line to the beginning of your website&#8217;s root <code>.htaccess</code> file:</p>
<p><code>AddHandler application/x-httpd-php53 .php</code></p>
<p>After making this change you can test it using <code>phpinfo()</code> and it will show you the version at the top, and as of the time of this post Hostmonster is keeping right up to date, running version 5.3.9.</p>
<p>This is exciting news for Zend programmers and other PHP developers ready for the upgrade. Enjoy!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2012/01/27/how-to-enable-php-5-3-on-hostmonster-shared-web-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Bookmark your Facebook News Feed</title>
		<link>http://www.warpconduit.net/2011/09/27/how-to-bookmark-your-facebook-news-feed/</link>
		<comments>http://www.warpconduit.net/2011/09/27/how-to-bookmark-your-facebook-news-feed/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 22:27:53 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[home page]]></category>
		<category><![CDATA[news feed]]></category>
		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=409</guid>
		<description><![CDATA[Recently Facebook underwent some design changes, now whenever you login to Facebook you are dropped on the Welcome page. Also if you are already logged in and go to http://www.facebook.com it also drops you on the Welcome page. But when you click on the link for News Feed the URL registers as http://www.facebook.com. But for [...]]]></description>
			<content:encoded><![CDATA[<p>Recently Facebook underwent some design changes, now whenever you login to Facebook you are dropped on the Welcome page. Also if you are already logged in and go to <a href="http://www.facebook.com">http://www.facebook.com</a> it also drops you on the Welcome page.</p>
<p>But when you click on the link for News Feed the URL registers as <a href="http://www.facebook.com">http://www.facebook.com</a>. But for those of us who prefer the News Feed when going to the normal Facebook URL this is annoying, and I&#8217;ve found no help or settings that allows me to choose the default section that Facebook will initially load.</p>
<p>So after some messing around i found that the URL for the actual Facebook News Feed:</p>
<p><a href="http://www.facebook.com/?sk=nf">http://www.facebook.com/?sk=nf</a></p>
<p>Just click that link once you&#8217;re logged in to Facebook, bookmark the page, and you&#8217;ll be able to go directly to your News Feed using that bookmark; that is unless Facebook makes changes rendering this method useless.</p>
<p>It works for me, hope that information helps someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/09/27/how-to-bookmark-your-facebook-news-feed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prevent Windows Update from Automatically Rebooting Your PC</title>
		<link>http://www.warpconduit.net/2011/08/03/prevent-windows-update-from-automatically-rebooting-your-pc/</link>
		<comments>http://www.warpconduit.net/2011/08/03/prevent-windows-update-from-automatically-rebooting-your-pc/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 18:51:29 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[windows 2008]]></category>
		<category><![CDATA[windows 7]]></category>
		<category><![CDATA[windows update]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=397</guid>
		<description><![CDATA[In Windows Server 2008 and Windows 7 your computer may automatically install Window&#8217;s Updates and then restart.  Follow one of the methods below to disable this behavior.  These instructions are for computer experts only. Method 1 Run gpedit.msc Go to Local Computer Policy -&#62; Computer Configuration -&#62; Administrative Templates -&#62; Windows Components -&#62; Windows Update [...]]]></description>
			<content:encoded><![CDATA[<p>In Windows Server 2008 and Windows 7 your computer may automatically install Window&#8217;s Updates and then restart.  Follow one of the methods below to disable this behavior.  These instructions are for computer experts only.</p>
<h2>Method 1</h2>
<ol>
<li>Run <code>gpedit.msc</code></li>
<li>Go to <strong>Local Computer Policy -&gt; Computer Configuration -&gt; Administrative Templates -&gt; Windows Components -&gt; Windows Update</strong></li>
<li>Double-click on <strong>&#8220;No auto-restart for scheduled Automatic Update installation&#8221;</strong></li>
<li>Enable it, click OK and close the Group Policy Editor</li>
<li>Reboot</li>
</ol>
<h2>Method 2</h2>
<p>If you don&#8217;t have <code>gpedit.msc</code>, use the following instructions.</p>
<ol>
<li>Run <code>regedit.exe</code></li>
<li>Go to <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU</strong><br />
<strong>Note:</strong> You will need to create the <strong>WindowsUpdate</strong> and <strong>AU</strong> keys if they are missing.</li>
<li>Create a new <strong>32-bit DWORD</strong> value inside of <strong>WindowsUpdate\AU </strong>and name it <strong>NoAutoRebootWithLoggedOnUsers</strong></li>
<li>Double-click on your newly created value and give it a <em>value data</em> of 1 (hexadecimal)</li>
<li>Click OK and close Registry Editor</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/08/03/prevent-windows-update-from-automatically-rebooting-your-pc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Redirection and Error Page On Empty WordPress Search</title>
		<link>http://www.warpconduit.net/2011/08/02/fix-redirection-and-error-page-on-empty-wordpress-search/</link>
		<comments>http://www.warpconduit.net/2011/08/02/fix-redirection-and-error-page-on-empty-wordpress-search/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 18:08:34 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=387</guid>
		<description><![CDATA[I found out just recently that in some cases when you perform a blank search on a WordPress site you are redirected to the front page with an error message. If you encounter this issue simply apply the fix below, which modifies the blank search into a search for one space. This is enough to [...]]]></description>
			<content:encoded><![CDATA[<p>I found out just recently that in some cases when you perform a blank search on a WordPress site you are redirected to the front page with an error message. If you encounter this issue simply apply the fix below, which modifies the blank search into a search for one space. This is enough to resolve the error page and land you on the search page.</p>
<p>Add the following code to your theme&#8217;s <code>functions.php</code> file to fix this annoying behavior:</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: #339933;">!</span>is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'search_query_fix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">function</span> search_query_fix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/08/02/fix-redirection-and-error-page-on-empty-wordpress-search/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>APT Repository for Old Ubuntu Releases</title>
		<link>http://www.warpconduit.net/2011/07/31/apt-repository-for-old-ubuntu-releases/</link>
		<comments>http://www.warpconduit.net/2011/07/31/apt-repository-for-old-ubuntu-releases/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 23:27:35 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[ubuntu repository old apt]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=378</guid>
		<description><![CDATA[Recently I installed Ubuntu Server 6.06 (Dapper) on an old Sun Blade 100 which has a SPARC processor. The installation on a Sun Blade 100 has its own quirks, but after getting it up and running I of course wanted to make sure it had the latest software versions and security updates that it could [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I installed Ubuntu Server 6.06 (Dapper) on an old Sun Blade 100 which has a SPARC processor.  The installation on a Sun Blade 100 has its own quirks, but after getting it up and running I of course wanted to make sure it had the latest software versions and security updates that it could support.</p>
<h3>Problem</h3>
<p>After support for an old Ubuntu releases has been dropped the folks at Canonical remove the repositories from their main repository servers such as <code>archive.ubuntu.com</code> and <code>security.ubuntu.com</code>.  So, when you run <code>sudo apt-get update</code> you are met with a list of errors telling you that the your configured repositories were not found.</p>
<h3>Solution</h3>
<p>To get back on the repository train, edit your <code>/etc/apt/sources.list</code> and replace all instances of <code>archive.ubuntu.com</code> and <code>security.ubuntu.com</code> with the very fitting <code>old-releases.ubuntu.com</code>.  After that, run <code>sudo apt-get update</code> and watch the repository indexes roll in!</p>
<p>Here is an example of an updated <code>/etc/apt/sources.list</code> for Ubuntu 6.06 (Dapper):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">## Uncomment the following two lines to fetch updated software from the network</span>
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper main restricted
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper main restricted
&nbsp;
<span style="color: #808080; font-style: italic;">## Uncomment the following two lines to fetch major bug fix updates produced</span>
<span style="color: #808080; font-style: italic;">## after the final release of the distribution.</span>
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-updates main restricted
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-updates main restricted
&nbsp;
<span style="color: #808080; font-style: italic;">## Uncomment the following two lines to add software from the 'universe'</span>
<span style="color: #808080; font-style: italic;">## repository.</span>
<span style="color: #808080; font-style: italic;">## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu</span>
<span style="color: #808080; font-style: italic;">## team, and may not be under a free licence. Please satisfy yourself as to</span>
<span style="color: #808080; font-style: italic;">## your rights to use the software. Also, please note that software in</span>
<span style="color: #808080; font-style: italic;">## universe WILL NOT receive any review or updates from the Ubuntu security</span>
<span style="color: #808080; font-style: italic;">## team.</span>
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper universe
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper universe
&nbsp;
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-security main restricted
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-security main restricted
&nbsp;
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-security universe
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-security universe
&nbsp;
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper multiverse
deb-src http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper multiverse
&nbsp;
deb http://old-releases.<span style="color: black;">ubuntu</span>.<span style="color: black;">com</span>/ubuntu dapper-backports main restricted universe multiverse</pre></div></div>

<p>That&#8217;s it for today, I hope this has helped you get the software you need onto an old Ubuntu installation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/07/31/apt-repository-for-old-ubuntu-releases/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Setup WordPress to Respond to Multiple Site URLs</title>
		<link>http://www.warpconduit.net/2011/07/23/setup-wordpress-to-respond-to-multiple-site-urls/</link>
		<comments>http://www.warpconduit.net/2011/07/23/setup-wordpress-to-respond-to-multiple-site-urls/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 01:53:59 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=368</guid>
		<description><![CDATA[Have you ever encountered a case where you want to access your WordPress site from multiple site URLs (for example a local URL and an external URL, or multiple external URLs)? Solution Change the Site URL and Home URL to a relative URL, making the domain name irrelevant to loading the site. Oh, but it [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever encountered a case where you want to access your WordPress site from multiple site URLs (for example a local URL and an external URL, or multiple external URLs)?</p>
<h3>Solution</h3>
<p>Change the Site URL and Home URL to a relative URL, making the domain name irrelevant to loading the site. Oh, but it can&#8217;t be as simple as updating that on the Settings->General admin page, no&#8230;WordPress requires a valid URL.  Well don&#8217;t give up, you&#8217;ll just have to hack the option directly in the database.</p>
<ol>
<li>Connect to your WordPress database using a web-based utility like phpMyAdmin or another SQL client such as HeidiSQL.</li>
<li>Open your <code>wp_options</code> table for editing (if applicable, use your table prefix instead of <code>wp_</code>).</li>
<li>Find the rows with an <code>option_name</code> of <code>siteurl</code> or <code>home</code> and change the <code>option_value</code> of each to <code>/</code> if WordPress is installed in the root of your website or <code>/path/to/wordpress</code> if your WordPress site is installed in a sub-directory. <strong> Do NOT add a trailing slash.</strong></li>
<li>For those wanting to execute a simple SQL query, here is an example:

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> wp_options <span style="color: #993333; font-weight: bold;">SET</span> option_value <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'/'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> option_name <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'siteurl'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'home'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</li>
<li>Test your site out by going to your site URLs (for example http://192.168.0.1, http://mywebserver.local, http://www.example.com).</li>
</ol>
<p><strong>Important Note:</strong> This method is a hack and therefore isn&#8217;t a behavior WordPress developers intended.  I wouldn&#8217;t recommend it for a production site. I have noticed that after making this change on a site that the admin login page lacks CSS, the toolbar on the Visual Editor is missing, and the front-end admin bar sometimes fails to be styled and shows at the bottom on pages.  I haven&#8217;t seen any issues with the normal front-end site that visitors see.  So be aware of some admin CSS problems.</p>
<p>Hope that tip can help some of you out, I know it was useful to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/07/23/setup-wordpress-to-respond-to-multiple-site-urls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selecting Random Rows Using MySQL + Benchmark Results</title>
		<link>http://www.warpconduit.net/2011/03/23/selecting-a-random-record-using-mysql-benchmark-results/</link>
		<comments>http://www.warpconduit.net/2011/03/23/selecting-a-random-record-using-mysql-benchmark-results/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 00:13:48 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[rows]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=309</guid>
		<description><![CDATA[A topic of contention that has been around for many years is that of using ORDER BY RAND() to select random rows. This method is said to be very slow, doesn&#8217;t scale well and should not be used. Is this the case? Does it have its uses? Well, they say the proof is in the [...]]]></description>
			<content:encoded><![CDATA[<p>A topic of contention that has been around for many years is that of using <code>ORDER BY RAND()</code> to select random rows. This method is said to be very slow, doesn&#8217;t scale well and should not be used. Is this the case? Does it have its uses? Well, they say the <a href="http://www.phrases.org.uk/meanings/proof-of-the-pudding.html" target="_blank">proof is in the pudding</a>, so let&#8217;s get to the pudding.</p>
<h2>Contenders</h2>
<h3>Order by Rand() Method</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>;</pre></div></div>

<p>This method works by generating a random value for each row of the table, sorting the table according to these random values, and then returning one row.</p>
<p><strong>Advantage:</strong> Easy to remember and use in complicated SQL queries and you don&#8217;t need to have a uniquely assigned or auto-incrementing ID field in your table.  Easily select multiple random rows by simply increasing the <code>LIMIT</code>.</p>
<p><strong>Disadvantage:</strong> This method&#8217;s speed is directly related to how long it takes to generate a random value for each row. The more rows a table has the longer it takes.</p>
<h3>Order By Rand() Alternative Method</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">WHERE</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>;</pre></div></div>

<p>This method uses <code>ORDER BY RAND()</code>, but only on a small percentage of the table rows; this percentage is based upon how many rows you want, <code>LIMIT 1</code>, divided by how many rows the table has, <code>COUNT(*)</code>, and then multiply that figure by 10 to avoid returning less rows than you request. I developed this method after reading <a href="http://www.rndblog.com/how-to-select-random-rows-in-mysql/" target="_blank">How to select random rows in MySQL @ rndblog.com</a>.</p>
<p><strong>Advantage:</strong> Easy to use in complicated SQL queries and you don&#8217;t need to have a sequentially numbered field in your table.  Easily select multiple random rows by simply increasing the <code>LIMIT</code> and adjusting the <code>WHERE</code> statement to match. For example, to get 30 random rows you would use:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">WHERE</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">/</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">30</span>;</pre></div></div>

</p>
<p><strong>Disadvantage:</strong> This method&#8217;s speed is directly related to how long it takes to generate a random value for each row you query. The more random rows you want, the longer it takes.</p>
<h3>Inner Join Method</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">AS</span> t <span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> ROUND<span style="color: #66cc66;">&#40;</span>RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> x <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">&gt;=</span> x<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>;</pre></div></div>

<p>This method smartly uses the primary key (id column) to generate a random integer based upon the highest number in your key field and assigns a table alias so that you can use it to select one row where the key matches the previously generated random integer.</p>
<p>Note that you many also express this method as a sub-query like so:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">AS</span> t<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> ROUND<span style="color: #66cc66;">&#40;</span>RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> x <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">&gt;=</span> x<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>;</pre></div></div>

<p>Depending on your SQL query one way may be easier to integrate than the other.</p>
<p><strong>Advantage:</strong> Doesn&#8217;t spend time generating a random value for each row. See benchmark results.</p>
<p><strong>Disadvantage:</strong> Requires that your table have an auto-incrementing primary key field or other sequentially numbered field and it must have no holes (must be 1, 2, 3, 4&#8230; not 3, 8, 11, 34&#8230;) in the sequence of integers. Must run query multiple times to get more than one random row, increasing the limit will only give you sequential rows starting from the randomly selected row. May be difficult for a beginner to integrate into an already complicated SQL query.</p>
<h3>User Variable Method</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> ROUND<span style="color: #66cc66;">&#40;</span>RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> num<span style="color: #66cc66;">,</span> @num:<span style="color: #66cc66;">=</span>@num<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> @num:<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> a<span style="color: #66cc66;">,</span> myTable <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> b<span style="color: #66cc66;">,</span> myTable <span style="color: #993333; font-weight: bold;">AS</span> t <span style="color: #993333; font-weight: bold;">WHERE</span> b<span style="color: #66cc66;">.</span>num <span style="color: #66cc66;">=</span> t<span style="color: #66cc66;">.</span>id;</pre></div></div>

<p>This method uses user-defined variables to generate a number of random integers defined by the <code>LIMIT</code> and uses those integers to match rows with the table&#8217;s id field. For a little more information about this method check out <a href="http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/">How to produce random rows from a table @ MySQL Diary</a>.</p>
<p><strong>Advantage:</strong> Doesn&#8217;t spend time generating a random value for each row. Can be used to get multiple random rows (on tables with no numbering holes) by increasing the <code>LIMIT</code> within the inner <code>SELECT</code>. See benchmark results.</p>
<p><strong>Disadvantage:</strong> User-defined variables are connection specific, so you can&#8217;t use this method with connection pooling or persistent connections. Requires that your table have an auto-incrementing primary key field or other sequentially numbered field and it must have no holes (must be 1, 2, 3, 4&#8230; not 3, 8, 11, 34&#8230;) in the sequence of integers. May be time consuming to integrate into an existing SQL query.</p>
<h2>Setup</h2>
<p>With the help of <a href="http://www.generatedata.com/">GenerateData</a> I was able to generate a fictional customer data table with 1,250,000 rows (MyISAM engine, latin1_swedish_ci collation). I then used HeidiSQL to run each of the random row methods 10 times, recorded the query execution time of each run and extracted an average run time for each method. You can see a sample of the generated customer data below:</p>
<div id="attachment_332" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.warpconduit.net/wp-content/uploads/customer-database-sample-generated-data.png" rel="shadowbox[sbpost-309];player=img;"><img src="http://www.warpconduit.net/wp-content/uploads/customer-database-sample-generated-data-600x150.png" alt="Customer Database Sample Generated Data" title="Customer Database Sample Generated Data" width="600" height="150" class="size-large wp-image-332" /></a><p class="wp-caption-text">Click image to enlarge</p></div>
<p>Also, using the main customer table, I created intermediate tables with 10, 100, 500, 1,000, 2,000, 3,000, 4,000, 5,000, 10,000, 25,000, 50,000, 100,000, 250,000, 500,000, and 1,000,000 rows and tested these the same way.</p>
<h2>Results: Part 1</h2>
<p>Below you can see the overall performance chart of all three methods and a partial chart showing just the performance on tables with 10-50,000 rows. <a href="https://spreadsheets.google.com/ccc?key=0AsNZEFAM2gksdExkbVpEMW00MGlMQ3N5VUNlQ0xJbVE&#038;hl=en" target="_blank">View Detailed Results on a Google Docs Spreadsheet</a>. A value of zero means the query time was too fast to be measured by HeidiSQL (less than one-thousandth of a second).</p>
<h4>Full Chart</h4>
<div id="attachment_327" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.warpconduit.net/wp-content/uploads/mysql-random-row-benchmark-full-results.png" rel="shadowbox[sbpost-309];player=img;"><img src="http://www.warpconduit.net/wp-content/uploads/mysql-random-row-benchmark-full-results-600x442.png" alt="MySQL Random Row Benchmark Full Chart" title="MySQL Random Row Benchmark Full Chart" width="600" height="442" class="size-large wp-image-327" /></a><p class="wp-caption-text">Click image to enlarge</p></div>
<h4>Partial Chart</h4>
<div id="attachment_328" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.warpconduit.net/wp-content/uploads/mysql-random-row-benchmark-partial-results.png" rel="shadowbox[sbpost-309];player=img;"><img src="http://www.warpconduit.net/wp-content/uploads/mysql-random-row-benchmark-partial-results-600x197.png" alt="MySQL Random Row Benchmark Partial Chart" title="MySQL Random Row Benchmark Partial Chart" width="600" height="197" class="size-large wp-image-328" /></a><p class="wp-caption-text">Click image to enlarge</p></div>
<p>The <strong>Inner Join</strong> and <strong>User Variable</strong> methods certainly show themselves to be optimized and speedy; getting a random row from 1.25 million records in a little over one thousandth of a second. Either of these methods would be great to use on a table with a sequentially numbered field with no numbering holes. If you do have numbering holes in your primary key and would like to avoid using <code>ORDER BY RAND()</code> then <a href="http://jan.kneschke.de/" target="_blank">Jan Kneschke</a> has a method for you involving <a href="http://jan.kneschke.de/projects/mysql/order-by-rand/" target="_blank">building a mapping table to fill the numbering holes and triggers to keep it updated</a>.</p>
<p>We can see that the <strong>Order By Rand()</strong> method is not efficient and doesn&#8217;t scale well, no question about that, but it is the easiest method to remember and use, and you can get multiple random rows without worrying about numbering holes in your primary key.  Calling the <strong>Order By Rand()</strong> method slow would be a relative statement because in smaller tables it is still relatively fast; under 1/100th of a second when querying up to 2000 rows.  I personally wouldn&#8217;t hesitate to use it in tables having as many as 5,000 rows.</p>
<p>We certainly can&#8217;t overlook the <strong>Order By Rand() Alternative</strong> method; it is a great option that gives you an easy solution for multiple random rows and it performs up to 16x better than the regular <strong>Order By Rand()</strong> method.</p>
<h2>What about multiple random rows?</h2>
<p>Yes, this is a very important question. Let&#8217;s have a fictional customer appreciation day and pick 100 random customers out of the 1.25 million customers to send gift certificates to. How would I go about accomplishing that? To give all of the methods ideal conditions we&#8217;ll assume that the customer table were working with has a primary key with no numbering holes, so for the <strong>Order By Rand()</strong> and <strong>Order By Rand() Alternative</strong> methods you will just increase the <code>LIMIT</code> to 100. Note that in the alternative method you&#8217;ll also need to adjust the <code>WHERE</code> statement to match the <code>LIMIT</code> like so: <code>RAND()<(SELECT ((100/COUNT(*))*10) FROM myTable)</code></p>
<p>For the <strong>Inner Join</strong> method you'll have to run it 100 times to get 100 random rows, and for the <strong>User Variable</strong> you can just increase the <code>LIMIT</code> within the inner <code>SELECT</code> because there are no numbering holes.  If there were numbering holes you would have to run the <strong>User Variable</strong> method 100 times just like the <strong>Inner Join</strong> method.</p>
<p>To benchmark the selection of multiple rows I setup a PHP script to run the queries and print out the execution time of those commands. <a href="https://gist.github.com/878687" target="_blank">View the Multiple Random Rows MySQL PHP Benchmark Script</a>.</p>
<p><img src="http://chart.apis.google.com/chart?chxr=0,0,10&#038;chxt=y&#038;chbh=a&#038;chs=400x200&#038;cht=bvg&#038;chco=76A4FB,7777CC,80C65A,990066&#038;chds=0,10,0,10,0,10,0,10&#038;chd=t:9.761|0.614|0.015|0.002&#038;chdl=ORDER+BY+RAND()|ORDER+BY+RAND()+ALT|INNER+JOIN|USER+VARIABLE&#038;chtt=100+Random+Rows+MySQL+Benchmark" width="400" height="200" alt="100 Random Rows MySQL Benchmark" /><br />
<strong>Order By Rand():</strong> 9.761297 seconds<br />
<strong>Order By Rand() Alternative:</strong> 0.613716 seconds<br />
<strong>Inner Join:</strong> 0.015041 seconds<br />
<strong>User Variable:</strong> 0.001578 seconds</p>
<p>We can see here that the methods using <code>ORDER BY RAND()</code> simply can't keep up with awesome performance of the <strong>Inner Join</strong> and <strong>User Variable</strong> methods, in fact they don't even show up on the chart because the value is so small. It is important to note that if the customer table we were using had numbering holes, which I think about 90+% of tables do, then the <strong>Inner Join</strong> and <strong>User Variable</strong> methods could not be used.</p>
<h2>Winner</h2>
<p>From my perspective the <strong>Order By Rand() Alternative</strong> method is the overall winner here because it is easy to use and gives you quick results on small tables and very large tables whether you want a single random row or multiple random rows, and for selecting multiple random rows from large tables with numbering holes there is no better method.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable <span style="color: #993333; font-weight: bold;">WHERE</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> myTable<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>;</pre></div></div>

<h2>Conclusion</h2>
<p>Always choose your method depending on your table structure, number of table rows you are querying, how many random rows you need, and always weigh the ease of use against performance.</p>
<p>Thanks for reading!</p>
<p>Have another method you'd like to share? Leave a comment and let us know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/03/23/selecting-a-random-record-using-mysql-benchmark-results/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Get File Extension with PHP + Benchmark Results</title>
		<link>http://www.warpconduit.net/2011/02/27/get-file-extension-with-php-benchmark-results/</link>
		<comments>http://www.warpconduit.net/2011/02/27/get-file-extension-with-php-benchmark-results/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 00:06:46 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=297</guid>
		<description><![CDATA[I know you&#8217;ve probably seen this topic a hundred times, and so have I, but this one has a different twist.  We already know that there are many ways to get the extension of a file, but which one is the fastest?  That&#8217;s what I&#8217;m going to address right now. Contenders In each of the [...]]]></description>
			<content:encoded><![CDATA[<p>I know you&#8217;ve probably seen this topic a hundred times, and so have I, but this one has a different twist.  We already know that there are many ways to get the extension of a file, but which one is the fastest?  That&#8217;s what I&#8217;m going to address right now.</p>
<h2>Contenders</h2>
<p>In each of the code examples <code>$file</code> is set to <code>c:\\xampplite\\htdocs\\index.php</code>.</p>
<h3>String-to-Array Method</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// outputs 'php'</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Sub-String Method</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// outputs 'php'</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Path Info Method</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// outputs 'php'</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Setup</h2>
<p>To test each of the contenders I put together a script that timed the execution of 1,000,000 iterations of each command. If you would like the script you can download it <a href="https://gist.github.com/846721" target="_blank">here</a>.</p>
<h2>Results</h2>
<p><img src="http://chart.apis.google.com/chart?chxr=0,0,3&amp;chxt=y&amp;chbh=a&amp;chs=400x225&amp;cht=bvg&amp;chco=3399CC,FF9900,990066&amp;chds=0,3,0,3,0,3&amp;chd=t:0.778|1.89|2.02&amp;chdl=Sub-String|String-to-Array|Path+Info&amp;chtt=Get+File+Extension+PHP+Benchmark" alt="Get File Extension PHP Benchmark" width="400" height="225" /><br />
<strong>Sub-String Method:</strong> 0.778156 seconds<br />
<strong>String-to-Array Method:</strong> 1.889744 seconds<br />
<strong>Path Info Method:</strong> 2.020036 seconds</p>
<h2>Winner</h2>
<p>Our winner? The <strong>Sub-String Method</strong>! Next time you reach for that line of code to get a file&#8217;s extension, go for gold, and choose the <strong>Sub-String Method</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// outputs 'php'</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/02/27/get-file-extension-with-php-benchmark-results/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Increase Image Upload File Size Limit on OpenCart 1.4.9.3</title>
		<link>http://www.warpconduit.net/2011/02/04/increase-image-upload-file-size-limit-on-opencart/</link>
		<comments>http://www.warpconduit.net/2011/02/04/increase-image-upload-file-size-limit-on-opencart/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 16:05:52 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[opencart]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=271</guid>
		<description><![CDATA[OpenCart&#8217;s default image upload size is 300KB and that is simply too small for clients that don&#8217;t have the knowledge to resize their images before uploading them. Although uploading digital camera images does use more bandwidth, sometimes it can not be avoided. To adjust the image upload size make the following changes around line 446 [...]]]></description>
			<content:encoded><![CDATA[<p>OpenCart&#8217;s default image upload size is 300KB and that is simply too small for clients that don&#8217;t have the knowledge to resize their images before uploading them.  Although uploading digital camera images does use more bandwidth, sometimes it can not be avoided.  To adjust the image upload size make the following changes around line 446 of <code>admin/controller/common/filemanager.php</code>:</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10485760</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$json</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error_file_size'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case we have increased the upload size limit to 10MB, also make sure that your php configuration will <a href="http://www.radinks.com/upload/config.php" target="_blank">allow file uploads and posts of this size</a>.</p>
<p>Now you have these big images uploaded, but sometimes GD can run out of memory trying to resize these large images.  You can solve this by using imagemagick, if available. So what we&#8217;re going to do is resize all images larger than 1000&#215;1000 down to 1000&#215;1000.  Make the following changes around line 490 of <code>admin/controller/common/filemanager.php</code>:</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$imageinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageinfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1000</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$imageinfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'convert -colorspace RGB &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; -resize 1000x1000 &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$directory</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
		<span style="color: #000088;">$json</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_uploaded'</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>
		<span style="color: #000088;">$json</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error_uploaded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it, your image upload file size limit has been lifted and memory usage issues have been dealt with!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/02/04/increase-image-upload-file-size-limit-on-opencart/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic Category Images for OpenCart 1.4.9.3</title>
		<link>http://www.warpconduit.net/2011/02/01/automatic-category-images-for-opencart/</link>
		<comments>http://www.warpconduit.net/2011/02/01/automatic-category-images-for-opencart/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 22:53:56 +0000</pubDate>
		<dc:creator>Josh Hartman</dc:creator>
				<category><![CDATA[Web Design & Development]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[opencart]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.warpconduit.net/?p=265</guid>
		<description><![CDATA[The changes set forth below will cause OpenCart to assign a random product image from the category as the category image if one has not already been set. If the category contains no products, no_image.jpg will still display. Make the following changes around line 112 of catalog/controller/product/category.php. foreach &#40;$results as $result&#41; &#123; if &#40;$result&#91;'image'&#93;&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>The changes set forth below will cause OpenCart to assign a random product image from the category as the category image if one has not already been set.  If the category contains no products, <code>no_image.jpg</code> will still display.</p>
<p>Make the following changes around line 112 of <code>catalog/controller/product/category.php</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* START AUTOMATIC CATEGORY IMAGES */</span>
      		<span style="color: #000088;">$catimg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model_catalog_product</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRandomProductImageByCategoryId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$catimg</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      			<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$catimg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      			<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'no_image.jpg'</span><span style="color: #339933;">;</span>
      		<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* END AUTOMATIC CATEGORY IMAGES */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'href'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model_tool_seo_url</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rewrite</span><span style="color: #009900;">&#40;</span>HTTP_SERVER <span style="color: #339933;">.</span> <span style="color: #0000ff;">'index.php?route=product/category&amp;path='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'thumb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model_tool_image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config_image_category_width'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config_image_category_height'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Add this function to <code>catalog/model/catalog/product.php</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRandomProductImageByCategoryId<span style="color: #009900;">&#40;</span><span style="color: #000088;">$category_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT p.image FROM &quot;</span> <span style="color: #339933;">.</span> DB_PREFIX <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;product p LEFT JOIN &quot;</span> <span style="color: #339933;">.</span> DB_PREFIX <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.image != '' AND p.date_available &lt;= NOW() AND p2c.category_id = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$category_id</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' ORDER BY RAND() LIMIT 1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it, enjoy your automatically generated and random category images!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpconduit.net/2011/02/01/automatic-category-images-for-opencart/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 731/885 objects using disk: basic

Served from: www.warpconduit.net @ 2012-02-06 13:07:51 -->
