<?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>Goran Halusa &#187; Work</title>
	<atom:link href="http://www.gorsgraphics.com/archives/category/work/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gorsgraphics.com</link>
	<description>PHP/MySQL and Node.js Programmer - Web Developer and Designer - Frederick, Maryland</description>
	<lastBuildDate>Thu, 22 Dec 2011 05:57:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Efficiently Selecting Random Rows From a MySQL Table</title>
		<link>http://www.gorsgraphics.com/archives/654</link>
		<comments>http://www.gorsgraphics.com/archives/654#comments</comments>
		<pubDate>Sat, 17 Dec 2011 04:15:57 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=654</guid>
		<description><![CDATA[It&#8217;s tempting to simply use MySQL&#8217;s RAND() function to select random records from a table. Consider the following query: However, when considering overhead, this is a rather expensive method to [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s tempting to simply use <a title="MySQL's RAND() function" href="http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand" target="_blank">MySQL&#8217;s RAND() function</a> to select random records from a table. Consider the following query:</p>
<pre class="brush: php; title: ; notranslate">
SELECT FLOOR(7 + (RAND() * 5));
</pre>
<p>However, when considering overhead, this is a rather expensive method to employ. This becomes glaringly apparent when dealing with large datasets.</p>
<p>One effective solution is to select the first and last ids, and let PHP generate the random integer (id).  Then, simply select the record using the random integer.</p>
<pre class="brush: php; title: ; notranslate">
public function getRandomRecords()
{
	// Select the first id in the target table
	$statement = $this-&gt;db-&gt;prepare(&quot;SELECT some_id
	  FROM table_name
	  ORDER BY some_id ASC LIMIT 1&quot;);
	$statement-&gt;execute();
	$lowest_id = $statement-&gt;fetch(PDO::FETCH_ASSOC);

	// Select the last id in the target table
	$statement = $this-&gt;db-&gt;prepare(&quot;SELECT some_id
	  FROM table_name
	  ORDER BY some_id DESC LIMIT 1&quot;);
	$statement-&gt;execute();
	$highest_id = $statement-&gt;fetch(PDO::FETCH_ASSOC);

	$records_array = array();

	while(true)
	{
	  // Generate a random integer
	  $random_id = rand( $lowest_id['some_id'], $highest_id['some_id'] );

	  // Check to see if the record exists
	  $statement = $this-&gt;db-&gt;prepare(&quot;SELECT col_one, col_two, etc...
		FROM table_name
		WHERE some_id = {$random_id}&quot;;
		$statement-&gt;execute();
		$result = $statement-&gt;fetchAll(PDO::FETCH_ASSOC);

	  // If it exists, add it to the array
	  if($result)
	  {
	    $records_array[] = $record;
	  }

	  $i++;

	  // If the array contains 5 records, stop
	  if(count($records_array) == 5)
	  {
	    break;
	  }
	}

	return $records_array;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/654/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing Large XML Files Using PHP</title>
		<link>http://www.gorsgraphics.com/archives/631</link>
		<comments>http://www.gorsgraphics.com/archives/631#comments</comments>
		<pubDate>Tue, 15 Nov 2011 02:14:03 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=631</guid>
		<description><![CDATA[I ran into a situation where I needed to parse a large (1 GB) XML file in order to extract the data into a MySQL table. As usual, I did [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a situation where I needed to parse a large (1 GB) XML file in order to extract the data into a <a title="MySQL: The world's most popular open source database." href="http://www.mysql.com/" target="_blank">MySQL</a> table. As usual, I did my initial round of research. First, I decided to use the <a title="The DOMDocument class" href="http://php.net/manual/en/class.domdocument.php" target="_blank">DOMDocument PHP class</a>.</p>
<h3>First Mistake</h3>
<p>For my testing, I used a small subset of the data&#8230; weighing in at a measly 24 records.</p>
<p>Initially, all of my tests ran quite nicely. Then I decided to throw the complete (1 GB) XML file at it. Epic fail&#8230; I mean, it ran well for a while, but eventually ran out of memory. (And, yes&#8230; I did increase the memory_limit* to 1.5 GB and max_execution_time* to 5 hours.) I feared this may happen.</p>
<p>The problem with utilizing DOMDocument on large XML files is that it loads the data into an array. While parsing, that array is growing. Not good when you&#8217;re dealing with massive XML files.</p>
<p>With this <strong>fail</strong> under my belt, I went back to the drawing board. Knowledge is power&#8230; knowledge is power&#8230; knowledge is power.</p>
<h3>My Next Move</h3>
<p><a title="PHP's XMLReader" href="http://www.php.net/manual/en/book.xmlreader.php" target="_blank">XMLReader</a>. From the PHP website: &#8221;The XMLReader extension is an XML Pull parser. The reader acts as a cursor going forward on the document stream and stopping at each node on the way.&#8221; OK, sounds <em>considerably more promising</em>.</p>
<h3>And Survey Says, Ding!</h3>
<pre class="brush: php; title: ; notranslate">

$file = &quot;PATH_TO_FILE&quot;;

$reader = new XMLReader();

$reader-&gt;open($file);

while( $reader-&gt;read() )

{

// Execute processing here

}

$reader-&gt;close();
</pre>
<p>After that, it was gravy. Well, aside from the additional logic that had to go into it. That&#8217;s <em>easily</em> a topic all of it&#8217;s own, perfect for perhaps a &#8220;Part 2&#8243; of this post. No promises though&#8230; unless, of course, incoming requests prompt for more information!</p>
<h4>* How to modify PHP&#8217;s &#8220;memory_limit&#8221; and &#8220;max_execution_time&#8221; on a per script basis</h4>
<pre class="brush: php; title: ; notranslate">

// Tweak some PHP configurations
ini_set('memory_limit','1536M'); // 1.5 GB
ini_set('max_execution_time', 18000); // 5 hours
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/631/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oh My Word!</title>
		<link>http://www.gorsgraphics.com/archives/439</link>
		<comments>http://www.gorsgraphics.com/archives/439#comments</comments>
		<pubDate>Wed, 22 Dec 2010 01:43:48 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=439</guid>
		<description><![CDATA[About a month ago, we ran into a problem with hyperlinks in a Microsoft Word document. Wait! What? H-y-p-e-r-l-i-n-k-s? Yup. The most basic operation known in the history of the [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_542" class="wp-caption alignleft" style="width: 484px"><img class="size-full wp-image-542" title="Microsoft Word Icon" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/12/Microsoft_Word_Icon_2.jpg" alt="Microsoft Word Icon" width="474" height="284" /><p class="wp-caption-text">Microsoft Word. A necessary evil... shame, shame.</p></div>
<p>About a month ago, we ran into a problem with hyperlinks in a Microsoft Word document. Wait! What? H-y-p-e-r-l-i-n-k-s? Yup. The most basic operation known in the history of the internet; the fundamental building block for information sharing in today&#8217;s technological landscape.</p>
<p>So, we decided to build a function in a web application which outputs a Microsoft Word document complete with links. Here&#8217;s the kicker. When we finally succeeded in generating the Word document, we opened it and tried the links. This produced some weird results and basically failed when linking back to our web application.</p>
<p>OK, here&#8217;s the deal. Have you ever noticed that whenever you click on a  link in a Microsoft Word document, a status bar appears at the bottom of  the document window? Have you ever wondered what in the world it&#8217;s  doing? I have, but never pursued finding out.</p>
<p>As it turns out, Microsoft Word first sends the request to one of Microsoft&#8217;s servers. Then, Microsoft&#8217;s server sends the request back to the intended location. The problem is that it sends the request back, which is now originating from Microsoft&#8217;s server, void of any session data. So, if the end-user is logged in with established session data, good luck in successfully routing the user to the target&#8230; at this point, the request is coming from another user-agent.</p>
<p>So, here&#8217;s what we had to do in PHP to remedy this rather perplexing situation:</p>
<p><code>if(stristr($_SERVER['HTTP_USER_AGENT'], 'Word'))<br />
{<br />
die();<br />
}</code></p>
<p>One can only speculate what Microsoft is doing with all of these requests. For some reason, I&#8217;m leaning towards the word &#8220;harvest&#8221;. I surely hope this helps and saves time for anyone who runs into this issue! Microsoft #fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/439/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Freelance Work: Rick&#8217;s Fish and Pet Supply</title>
		<link>http://www.gorsgraphics.com/archives/455</link>
		<comments>http://www.gorsgraphics.com/archives/455#comments</comments>
		<pubDate>Mon, 08 Nov 2010 23:35:53 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=455</guid>
		<description><![CDATA[Actually, this was a team effort. The visionary was my wife, Julia. I just helped with some of the heavier technical aspects. There&#8217;s more to be added to the website. [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_456" class="wp-caption alignleft" style="width: 550px"><a href="http://www.ricksfishandpet.com/" target="_blank"><img class="size-full wp-image-456 " title="Rick's Fish and Pet Supply" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/11/ricks_fish_and_pet.jpg" alt="Rick's Fish and Pet Supply" width="540" height="350" /></a><p class="wp-caption-text">Rick&#39;s Fish &amp; Pet Supply Website</p></div>
<p>Actually, this was a team effort. The visionary was my wife, Julia. I just helped with some of the heavier technical aspects. There&#8217;s more to be added to the website. This is just Phase 1. <a title="Rick's Fish and Pet Supply Website" href="http://www.ricksfishandpet.com/" target="_blank">Visit Rick&#8217;s Fish and Pet Supply&#8217;s Website</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/455/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trying MODx</title>
		<link>http://www.gorsgraphics.com/archives/393</link>
		<comments>http://www.gorsgraphics.com/archives/393#comments</comments>
		<pubDate>Thu, 23 Sep 2010 00:30:47 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=393</guid>
		<description><![CDATA[Don&#8217;t get me wrong, I love WordPress. However, I will say that the PHP programming behind WordPress is, how should I say this? Um&#8230; a little weak. So, I&#8217;m trying [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_394" class="wp-caption alignleft" style="width: 550px"><a href="http://modxcms.com/" target="_blank"><img class="size-full wp-image-394  " title="MODx Logo - Content Management System, Framework, and More" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/09/modx-logo-540x260.png" alt="MODx Logo - Content Management System, Framework, and More" width="540" height="260" /></a><p class="wp-caption-text">MODx: Content Management System, Framework, and More</p></div>
<p>Don&#8217;t get me wrong, I love WordPress. However, I will say that the PHP programming behind WordPress is, how should I say this? Um&#8230; a little weak. So, I&#8217;m trying out another CMS, <a title="MODx: Content Management System, Framework, and More" href="http://modxcms.com/" target="_blank">MODx</a>. We&#8217;ll see&#8230; more on this as things develop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/393/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Freelance Work: Vanessa Robison’s Website (Launched!)</title>
		<link>http://www.gorsgraphics.com/archives/390</link>
		<comments>http://www.gorsgraphics.com/archives/390#comments</comments>
		<pubDate>Sun, 19 Sep 2010 04:18:27 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/archives/390</guid>
		<description><![CDATA[UPDATE: Vanessa Robison&#8217;s website is now live! I must say, it looks great! Check it out!]]></description>
			<content:encoded><![CDATA[<div class="posterous_autopost">
<p><a href="http://www.vanessarobison.com/" target="_blank"><img src="http://posterous.com/getfile/files.posterous.com/temp-2010-09-18/JjAnBssxJfphJcfjqrlExHJinHqqnADnClFzmiEhDkEJGueAwFBrlcAcDDgu/Vanessa_Robison_Website.jpg.scaled500.jpg" alt="" width="500" height="325" /></a> UPDATE: Vanessa Robison&#8217;s website is now live! I must say, it looks great! <a title="Vanessa Robison's website" href="http://www.vanessarobison.com/" target="_blank">Check it out</a>!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/390/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Freelance Work: Vanessa Robison &#8211; Contemporary Christian Artist (Draft)</title>
		<link>http://www.gorsgraphics.com/archives/347</link>
		<comments>http://www.gorsgraphics.com/archives/347#comments</comments>
		<pubDate>Thu, 01 Jul 2010 16:53:30 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=347</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="/wp/wp-content/uploads/2010/07/vanessa_home_01.jpg" target="_blank"><img class="alignleft size-full wp-image-348" title="Vanessa Robison - Contemporary Christian Artist" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/07/vanessa_home_sm_01.jpg" alt="Vanessa Robison - Contemporary Christian Artist" width="540" height="405" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/347/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Freelance Work: Living Water Logo &#8220;Birth of a Hero&#8221;</title>
		<link>http://www.gorsgraphics.com/archives/320</link>
		<comments>http://www.gorsgraphics.com/archives/320#comments</comments>
		<pubDate>Fri, 04 Jun 2010 04:24:28 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=320</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="/wp/wp-content/uploads/2010/06/LW_logo_birth_hero_01.png" target="_blank"><img class="alignleft size-full wp-image-322" title="Living Water Logo: Birth of a Hero (540)" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/06/LW_logo_birth_hero_540_01.jpg" alt="Living Water Logo: Birth of a Hero - small version" width="540" height="131" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/320/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tek-X: Chicago, Illinois &#8211; May 18 &#8211; 21, 2010</title>
		<link>http://www.gorsgraphics.com/archives/316</link>
		<comments>http://www.gorsgraphics.com/archives/316#comments</comments>
		<pubDate>Sat, 29 May 2010 05:29:42 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=316</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="540" height="360" flashvars="host=picasaweb.google.com&#038;hl=en_US&#038;feat=flashalbum&#038;RGB=0x000000&#038;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fghalusa%2Falbumid%2F5476558360604064385%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/316/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Freelance Work: Living Water Logo &#8220;Liquid Metal&#8221; (rough draft)</title>
		<link>http://www.gorsgraphics.com/archives/305</link>
		<comments>http://www.gorsgraphics.com/archives/305#comments</comments>
		<pubDate>Sat, 08 May 2010 05:23:44 +0000</pubDate>
		<dc:creator>Gor</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.gorsgraphics.com/?p=305</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-306" title="Living Water Logo - Liquid Metal" src="http://www.gorsgraphics.com/wp/wp-content/uploads/2010/05/lw_logo_liquidmetal.jpg" alt="Living Water Logo - Liquid Metal" width="540" height="405" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gorsgraphics.com/archives/305/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

