<?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>Matt Shelton &#187; php</title>
	<atom:link href="http://www.mattshelton.net/tags/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattshelton.net</link>
	<description>scribbling geekery, things and stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 13:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Prime Time</title>
		<link>http://www.mattshelton.net/2008/05/19/prime-time/</link>
		<comments>http://www.mattshelton.net/2008/05/19/prime-time/#comments</comments>
		<pubDate>Mon, 19 May 2008 15:30:40 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[math]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/?p=80</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/math/" title="math">math</a></p>Every so often I go back through posts on my old blog, which is securely archived for my own random access. [There are some fairly good posts on it about technology that wouldn't make sense to re-post here, but are &#8230; <a href="http://www.mattshelton.net/2008/05/19/prime-time/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Every so often I go back through posts on my old blog, which is securely archived for my own random access. [There are some fairly good posts on it about technology that wouldn't make sense to re-post here, but are still a good reference for me.] I read one the other day that made me chuckle with geekish delight as I read:</p>
<blockquote><p>1,000,003 is the smallest seven-digit prime number I could think of, which, being completely impossible to wholly divide from, should take care of the repetitive quotes.</p></blockquote>
<p>Backstory: I used to have a random quote generator made up of stupid phrases I&#8217;d collected over time. Some were output from <code>fortune</code>, some from movies or tv shows, and others were stupid inside jokes. There were far too many Family Guy references, <abbr title="If I Remember Correctly">IIRC</abbr>. It played well to the quasi-personal, friends-oriented content I was producing at the time. Each quote was an entry in a MySQL table with a primary key which I used for retrieval based on this code:</p>
<pre class="brush: php; title: ; notranslate">srand((double)microtime()*1000000);
$tq_query = mysql_query(&quot;select count(qid) from quotes&quot;)
or die ('Invalid Query: ' . mysql_error());
$getQuote = sprintf(&quot;select quote from quotes where qid='%s';&quot;,
addslashes(rand(1, mysql_result($tq_query,0)-1)));
$gq_result = mysql_query($getQuote)
or die ('Invalid Query: ' . mysql_error());
echo mysql_result($gq_result,0);</pre>
<p><em>Aside: As I copy and paste this now, I wonder why I didn&#8217;t just do something like &#8220;SELECT quote FROM quotes ORDER BY rand() LIMIT 1&#8243;, putting the responsibility for randomness on MySQL&#8217;s already set up random seed? I may have been over-prioritizing database robustness on a site that never got more than a few hundred hits per day.</em></p>
<p>My girlfriend at the time (now my wife) noticed that the quotes didn&#8217;t actually <em>seem</em> that random and, in fact, the same few kept repeating themselves over and over again. I had noticed the same thing, but never felt that motivated to investigate. [She was, I think, between classes and it <em>bothered</em> her… so who am I to argue?]</p>
<p>After reading a bunch of threads on the PHP website, I reasoned that the problem was that I was seeding the random stack with an even number. Due to silly rounding and a padding value, the number most commonly returned out of this function was 24, which is incredibly un-prime. [Even cooler to the numbers nerd inside of me, 24 is the largest number divisible by all numbers less than its square root.] So.. following good number theory, I changed the seed value to 1000003, which is prime, and in few other ways special.</p>
<p>In additional retrospect, saying &#8220;that I could think of&#8221; was quite silly… The list of <a href="http://www.research.att.com/~njas/sequences/b003617.txt">smallest n-digit primes</a> is readily available, so this shouldn&#8217;t require much thought at all. If memory serves, I don&#8217;t believe I looked this up, and really, how hard should it be for someone who finds math fun to know that 100001 and 100002 aren&#8217;t prime [11 and 2 are lowest divisors, respectively]?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2008/05/19/prime-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 5 now out of beta at Nearly Free Speech</title>
		<link>http://www.mattshelton.net/2008/01/04/php-5-now-out-of-beta-at-nearly-free-speech/</link>
		<comments>http://www.mattshelton.net/2008/01/04/php-5-now-out-of-beta-at-nearly-free-speech/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 17:00:21 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[nfn]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/2008/01/04/php-5-now-out-of-beta-at-nearly-free-speech/</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/uncategorized/" title="uncategorized">uncategorized</a></p>My web host, which has a really interesting hosting model, has been beta-testing PHP5 for some time now. I don&#8217;t have as much time to play with it as I&#8217;d like, so I opted to stay out of the beta &#8230; <a href="http://www.mattshelton.net/2008/01/04/php-5-now-out-of-beta-at-nearly-free-speech/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My <a href="https://www.nearlyfreespeech.net/">web host</a>, which has a really interesting hosting model, has been beta-testing PHP5 for some time now. I don&#8217;t have as much time to play with it as I&#8217;d like, so I opted to stay out of the beta for now.</p>
<p>However, testing is complete, and PHP 5 (v5.2) support is now <a href="http://blog.nearlyfreespeech.net/2007/12/27/php-update-five-finally-fast-and-flexible/">out of beta</a> and is the default for all new sites. I just set up a new site not knowing this and everything in my PHP app is functioning as I&#8217;d expect. Groovy!</p>
<p>They&#8217;re also offering a CGI-based version which runs with safe_mode and open_basedir turned OFF, which is huge for some apps like Gallery, which used to be my web-based photo app of choice.</p>
<p>So, I&#8217;ll just flip the switch and see what happens. Why not, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2008/01/04/php-5-now-out-of-beta-at-nearly-free-speech/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

