<?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>Cory Collier &#187; php</title>
	<atom:link href="http://corycollier.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://corycollier.com</link>
	<description>Web Developer and System Administrator in Orlando, FL</description>
	<lastBuildDate>Mon, 12 Jul 2010 02:16:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Google Reader and Zend_Http_Client Saves Time</title>
		<link>http://corycollier.com/2008/11/google-reader-and-zend_http_client-saves-time/</link>
		<comments>http://corycollier.com/2008/11/google-reader-and-zend_http_client-saves-time/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 22:24:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reader]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend_http_client]]></category>

		<guid isPermaLink="false">http://corycollier.com/?p=281</guid>
		<description><![CDATA[I&#8217;ve been working a lot on Florida Death Metal lately. Part of that means that I need to know news, as it happens, from a lot of different sources. That can be difficult (and a pain in the ass) to keep track of. The last thing I want to do, is visit 50 different sites [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a lot on <a title="Florida Death Metal" href="http://floridadeathmetal.com">Florida Death Metal</a> lately. Part of that means that I need to know news, as it happens, from a lot of different sources. That can be difficult (and a pain in the ass) to keep track of. The last thing I want to do, is visit 50 different sites every 15 minutes to see if there&#8217;s any news I should know about.</p>
<p>The first thing I did, to filter input, was to setup a <a title="Google Reader" href="http://google.com/reader">Google Reader</a> account for Florida Death Metal. At least this allowed me to see updates from a variety of other sites in a single place. This also allows me to search through those new listings for keywords to bands and events I think are important to know about.</p>
<p>This still requires me to visit Google Reader, and parse through a lot of stuff (routinely over 1000 new items) to find out what&#8217;s going on in the world. The real dilemma I was having, was trying to implement an active alert system to news going on around me. The active part, was me actively searching through Google Reader for information relevant to Florida Death Metal. </p>
<p>Needless to say, this started to suck. I have a great full time job, a wonderful wife, and a million other things I like to do with my spare time. Spending my days and nights on Google Reader, struggling to keep up with news for a project blew.</p>
<p>I love Florida Death Metal. I&#8217;ve never been involved in something that means so much to me. However, there are only so many days in the week, and so much time in each of those days. I need a way to passively keep up with relevant news and events. I needed some automation, so I could spend time hanging drapes for Melissa, or having a beer with Rob.</p>
<p>Enter <a title="Zend Http Client" href="http://framework.zend.com/manual/en/zend.http.html">Zend_Http_Client</a> &#8230;.</p>
<p>One of my favorite programming tricks is breaking down requests to servers, and finding a way to do them programatically. So, I got to thinking about how I could parse through all of my stuff in Google Reader. For each of the views in Google Reader, there is an associated RSS feed. Well, that makes things simple enough. I could just grab the RSS feed and parse it. </p>
<p>One minor detail, the RSS feeds aren&#8217;t publicly available. You have to be logged in to use them. This makes sense. I imagine Google doesn&#8217;t want to be used as an aggregator of RSS feeds to be used as a proxy to other sites. Sorry :/</p>
<p>So, here&#8217;s a breakdown of what I needed to write a script to do:</p>
<ol>
<li>Login to Google</li>
<li>Grab the RSS Feed for &#8216;All Items&#8217;</li>
<li>Parse the RSS Feed for keywords relevant to Florida Death Metal</li>
<li>Email me alerts (if there are matches)</li>
</ol>
<p>Not too bad. So, Here&#8217;s the script I came up with. I hope you like it :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #00ff00; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Description: Script to parse through a google reader aggregation of content for keywords
Version: 1.0
Author: Cory Collier
Author URI: http://corycollier.com/
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Define the constants required for the script</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'GOOGLE_PASSWORD'</span><span style="color: #ffff00;">,</span> 	<span style="color: #00ffff;">'&lt;your password here&gt;'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'GOOGLE_RSS_URI'</span><span style="color: #ffff00;">,</span> 		<span style="color: #00ffff;">'&lt;the url for your google reader rss feed&gt;'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'GOOGLE_LOGIN_URI'</span><span style="color: #ffff00;">,</span>		<span style="color: #00ffff;">'https://www.google.com/accounts/ServiceLoginAuth?service=reader'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'GOOGLE_LOGIN_EMAIL'</span><span style="color: #ffff00;">,</span> 	<span style="color: #00ffff;">'&lt;your gmail account username / email&gt;'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'MAILER_FROM_ADDR'</span><span style="color: #ffff00;">,</span>		<span style="color: #00ffff;">'&lt;where the email should come from&gt;'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'MAILER_TO_ADDR'</span><span style="color: #ffff00;">,</span>		<span style="color: #00ffff;">'&lt;where the email should go to&gt;'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
<span style="color: #00ff00;">define</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'MAILER_SUBJECT'</span><span style="color: #ffff00;">,</span>		<span style="color: #00ffff;">'Google Reader Parsing'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
* a Zend Framework Installation _MUST_ be located on the include path for PHP
*/</span>
<span style="color: #ffff00;">require</span> <span style="color: #00ffff;">'Zend/Loader.php'</span><span style="color: #ffff00;">;</span>
Zend_Loader<span style="color: #ffff00;">::</span><span style="color: #ffffff;">registerAutoload</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Instantiate a new Zend_Http_Client, with the google login url</span>
<span style="color: #00ffff;">$client</span> <span style="color: #ffff00;">=</span> <span style="color: #00ff00; font-weight: bold;">new</span> Zend_Http_Client<span style="color: #ff00ff;">&#40;</span>GOOGLE_LOGIN_URI<span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Set the client cookie jar ...
 * Set the method to POST ..
 * Set the parameters to post with
 */</span>
<span style="color: #00ffff;">$client</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setCookieJar</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#41;</span>
	<span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setMethod</span><span style="color: #ff00ff;">&#40;</span>Zend_Http_Client<span style="color: #ffff00;">::</span><span style="color: #ffffff;">POST</span><span style="color: #ff00ff;">&#41;</span>
	<span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setParameterPost</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ff00;">array</span><span style="color: #ff00ff;">&#40;</span>
		<span style="color: #00ffff;">'continue'</span>		<span style="color: #ffff00;">=&gt;</span> GOOGLE_RSS_URI<span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'service'</span>		<span style="color: #ffff00;">=&gt;</span> <span style="color: #00ffff;">'reader'</span><span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'niu'</span>			<span style="color: #ffff00;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'hl'</span>			<span style="color: #ffff00;">=&gt;</span> <span style="color: #00ffff;">'en'</span><span style="color: #ffff00;">,</span> 
		<span style="color: #00ffff;">'Email'</span>		<span style="color: #ffff00;">=&gt;</span> GOOGLE_LOGIN_EMAIL<span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'Passwd'</span>		<span style="color: #ffff00;">=&gt;</span> GOOGLE_PASSWORD<span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'PersistentCookie'</span>	<span style="color: #ffff00;">=&gt;</span> <span style="color: #00ffff;">'yes'</span><span style="color: #ffff00;">,</span>
		<span style="color: #00ffff;">'asts'</span>			<span style="color: #ffff00;">=&gt;</span> <span style="color: #00ffff;">''</span>
<span style="color: #ff00ff;">&#41;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//make the login request, and store the response in the $response variable ...</span>
<span style="color: #00ffff;">$response</span> <span style="color: #ffff00;">=</span> <span style="color: #00ffff;">$client</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">request</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">'POST'</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//If the response was successful, change the uri value for the client object</span>
<span style="color: #666666; font-style: italic;">// to the appropriate rss file for parsing</span>
<span style="color: #00ffff;">$client</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setUri</span><span style="color: #ff00ff;">&#40;</span>GOOGLE_RSS_URI<span style="color: #ff00ff;">&#41;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Change the request method to GET</span>
		<span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setMethod</span><span style="color: #ff00ff;">&#40;</span>Zend_Http_Client<span style="color: #ffff00;">::</span><span style="color: #ffffff;">GET</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//send the request, and store the results of it</span>
<span style="color: #00ffff;">$response</span> <span style="color: #ffff00;">=</span> <span style="color: #00ffff;">$client</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">request</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Initialize an array of keywords to look for</span>
<span style="color: #00ffff;">$keywords</span> <span style="color: #ffff00;">=</span> <span style="color: #00ff00;">array</span> <span style="color: #ff00ff;">&#40;</span>
	<span style="color: #666666; font-style: italic;">//Whatever your keywords are you're looking for</span>
<span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//SimpleXML is great!</span>
<span style="color: #00ffff;">$sx</span> <span style="color: #ffff00;">=</span> simplexml_load_string <span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">$response</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">getBody</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Iterate through each of the retrieved entries</span>
<span style="color: #ffff00;">foreach</span> <span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">$sx</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">entry</span> <span style="color: #ffff00;">as</span> <span style="color: #00ffff;">$entry</span> <span style="color: #ff00ff;">&#41;</span> 
<span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Now, iterate through each of the defined keywords / keyphrases</span>
    <span style="color: #ffff00;">foreach</span> <span style="color: #ff00ff;">&#40;</span> <span style="color: #00ffff;">$keywords</span> <span style="color: #ffff00;">as</span> <span style="color: #00ffff;">$keyword</span> <span style="color: #ff00ff;">&#41;</span> 
    <span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//First, check to see if the title contains a keyword / keyphrase</span>
        <span style="color: #ffff00;">if</span> <span style="color: #ff00ff;">&#40;</span> <span style="color: #00ff00;">stristr</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#40;</span>string<span style="color: #ff00ff;">&#41;</span><span style="color: #00ffff;">$entry</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">title</span><span style="color: #ffff00;">,</span> <span style="color: #00ffff;">$keyword</span><span style="color: #ff00ff;">&#41;</span> <span style="color: #ff00ff;">&#41;</span> 
        <span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Append any matches to the matches arrays</span>
            <span style="color: #00ffff;">$matches</span><span style="color: #ff00ff;">&#91;</span><span style="color: #ff00ff;">&#93;</span> <span style="color: #ffff00;">=</span> <span style="color: #ff00ff;">&#40;</span>string<span style="color: #ff00ff;">&#41;</span><span style="color: #00ffff;">$entry</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">link</span><span style="color: #ff00ff;">&#91;</span><span style="color: #00ffff;">'href'</span><span style="color: #ff00ff;">&#93;</span><span style="color: #ffff00;">;</span>
        <span style="color: #ff00ff;">&#125;</span>
    	<span style="color: #666666; font-style: italic;">//Next, check to see if there are any matches in the summary</span>
        <span style="color: #ffff00;">if</span> <span style="color: #ff00ff;">&#40;</span> <span style="color: #00ff00;">stristr</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#40;</span>string<span style="color: #ff00ff;">&#41;</span><span style="color: #00ffff;">$entry</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">summary</span><span style="color: #ffff00;">,</span> <span style="color: #00ffff;">$keyword</span><span style="color: #ff00ff;">&#41;</span> <span style="color: #ff00ff;">&#41;</span> 
        <span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//same deal: If there are matches, add them to the stack</span>
            <span style="color: #00ffff;">$matches</span><span style="color: #ff00ff;">&#91;</span><span style="color: #ff00ff;">&#93;</span> <span style="color: #ffff00;">=</span> <span style="color: #ff00ff;">&#40;</span>string<span style="color: #ff00ff;">&#41;</span><span style="color: #00ffff;">$entry</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">link</span><span style="color: #ff00ff;">&#91;</span><span style="color: #00ffff;">'href'</span><span style="color: #ff00ff;">&#93;</span><span style="color: #ffff00;">;</span>
        <span style="color: #ff00ff;">&#125;</span>
    <span style="color: #ff00ff;">&#125;</span> <span style="color: #666666; font-style: italic;">//END keyword iteration</span>
&nbsp;
<span style="color: #ff00ff;">&#125;</span> <span style="color: #666666; font-style: italic;">// END posting iteration</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//IF matches were found, send an email</span>
<span style="color: #ffff00;">if</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ff00;">count</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">$matches</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ff00ff;">&#41;</span> 
<span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Initialize a variable to store a mesage in</span>
    <span style="color: #00ffff;">$message</span> <span style="color: #ffff00;">=</span> <span style="color: #00ffff;">''</span><span style="color: #ffff00;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Iterate through each of the matches</span>
    <span style="color: #ffff00;">foreach</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">$matches</span> <span style="color: #ffff00;">as</span> <span style="color: #00ffff;">$match</span><span style="color: #ff00ff;">&#41;</span>
    <span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//For each of the matches, append them to the message string, separated </span>
    	<span style="color: #666666; font-style: italic;">// by newlines</span>
        <span style="color: #00ffff;">$message</span> <span style="color: #ffff00;">.=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ffff00;">.</span>  <span style="color: #00ffff;">$match</span><span style="color: #ffff00;">;</span>  
    <span style="color: #ff00ff;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//Initialize a new Zend_Mail object </span>
    <span style="color: #00ffff;">$mail</span> <span style="color: #ffff00;">=</span> <span style="color: #00ff00; font-weight: bold;">new</span> Zend_Mail<span style="color: #ffff00;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Set the parameters necessary to send a message </span>
    <span style="color: #00ffff;">$mail</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">addTo</span><span style="color: #ff00ff;">&#40;</span>MAILER_TO_ADDR<span style="color: #ff00ff;">&#41;</span>
        <span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setFrom</span><span style="color: #ff00ff;">&#40;</span>MAILER_FROM_ADDR<span style="color: #ff00ff;">&#41;</span>
        <span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setSubject</span><span style="color: #ff00ff;">&#40;</span>MAILER_SUBJECT<span style="color: #ff00ff;">&#41;</span>
        <span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">setBodyText</span><span style="color: #ff00ff;">&#40;</span><span style="color: #00ffff;">$message</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//I never trust email, so wrap the email execution in a try/catch statement</span>
    try  
    <span style="color: #ff00ff;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Send the mail</span>
        <span style="color: #00ffff;">$mail</span><span style="color: #ffff00;">-&gt;</span><span style="color: #ff00ff;">send</span><span style="color: #ff00ff;">&#40;</span><span style="color: #ff00ff;">&#41;</span><span style="color: #ffff00;">;</span>   
    <span style="color: #ff00ff;">&#125;</span> catch <span style="color: #ff00ff;">&#40;</span>Exception <span style="color: #00ffff;">$e</span> <span style="color: #ff00ff;">&#41;</span><span style="color: #ff00ff;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//Do something here</span>
    <span style="color: #ff00ff;">&#125;</span>
<span style="color: #ff00ff;">&#125;</span></pre></div></div>

<p>Wrapping all of this up, I stuck this script on a spare <a title="Debian, The Most Awesome Linux Distribution Ever!" href="http://www.debian.org/">debian</a> box at my house, and setup a cronjob to run the script every 15 minutes. It saves me a lot of time. I&#8217;d love to hear some feedback from y&#8217;all about how I got this done. I&#8217;m a script guy at heart. So, this stuff is super fun for me.</p>
</pre>
<p>Wrapping all of this up, I stuck this script on a spare <a title="Debian, The Most Awesome Linux Distribution Ever!" href="http://www.debian.org/">debian</a> box at my house, and setup a cronjob to run the script every 15 minutes. It saves me a lot of time. I'd love to hear some feedback from y'all about how I got this done. I'm a script guy at heart. So, this stuff is super fun for me.</p>
<p>I know I should have checked the success of the initial login attempt before assuming the second request would get anything at all. Keep in mind though, this is a script I use to make my own life easier. Exceptions being thrown here cause me no harm. If I don't get anything, I can check my error logs for issues. Not a perfect solution, but it's working pretty well for me now. <img src='http://corycollier.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://corycollier.com/2008/11/google-reader-and-zend_http_client-saves-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Red Hat vs PDO vs PCRE vs Zend Lucene Search</title>
		<link>http://corycollier.com/2008/10/red-hat-vs-pdo-vs-pcre-vs-zend-lucene-search/</link>
		<comments>http://corycollier.com/2008/10/red-hat-vs-pdo-vs-pcre-vs-zend-lucene-search/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 01:37:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[pdo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[red hat]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://corycollier.com/?p=236</guid>
		<description><![CDATA[Recently while working at my new job at Hydra Studio, my buddy Rob and I came across an issue that was killing us:  &#8220;Invalid parameter number: no parameters were bound&#8221;  When people used our search feature on our site, a few specific search terms would result in un-caught exceptions. Of course, this ONLY happened on [...]]]></description>
			<content:encoded><![CDATA[<p>Recently while working at my new job at <a title="Hydra Studio, a web design and development studio in Orlando, FL" rel="co-worker" href="http://hydrastudio.com">Hydra Studio</a>, my buddy <a title="Rob Ziener, a brilliant web developer in Orlando, FL" rel="friend co-worker&lt;br &gt;&lt;/a&gt;" href="http://robzienert.com/">Rob</a> and I came across an issue that was killing us: </p>
<blockquote><p>&#8220;Invalid parameter number: no parameters were bound&#8221;</p></blockquote>
<p> When people used our search feature on our site, a few specific search terms would result in un-caught exceptions. Of course, this ONLY happened on the client&#8217;s server. Nothing like saying a project is solid, only to find out there&#8217;s something &#8216;special&#8217; about the production environment.</p>
<p>The first thing we did, was to list out what was unique about the client&#8217;s server. The client was using a Media Temple box running CentOS 5.2. For the un-initiated, CentOS is the free version of Red Hat Enterprise Server. We run Macs in the office, and our staging server is a Mac too. Other than the OS, the normal &#8216;LAMP&#8217; stuff pretty much matched verbatim. </p>
<p>So, we started digging into the differences between the compiled versions of PHP between the development and production environments, and one thing popped out at us:</p>
<p>PCRE</p>
<p>The version that&#8217;s supported on Red Hat / CentOS is 6.6. That&#8217;s horrible. 6.6 came out nearly 3 years ago, and the version the client was running had no support for unicode at all. A little research, and we found out that Zend Search Lucene (what we built the search functionality on top of) requires unicode for the way it stores search indexes.</p>
<p>With that, we figured we were done. The client had a limitation on their server, they needed to address it, and the problem would fix itself when they did. Not quite so fast &#8230;</p>
<p>I was testing some of the searching on my iMac, when the same issue happened on my own computer. Disaster! Could it be that something in our own code was the culprit? What half-reproducible error was causing this? </p>
<p>After <em>hours</em> of searching for an answer on the googlez, I came across some help on the <a href="http://framework.zend.com/issues/browse/ZF-1343">Zend Issue Tracker</a>. It turns out, that PDO was failing when it was trying to prepare a statement, when that statement contained a question mark. When I switched my SQL adapter to Mysqli, the problem was solved. Both the production and the development environments were bug free after the change.</p>
<p>It turns out, that our search indexes would return fields that either contained question marks, because they actually existed in the document (as was the case locally), or because the document had encoding errors when the search index was built (as was the case on the production servers). The ORM we used would grab the documents, and grab relevant data from the database by querying with the fields stored in the index.</p>
<p>The SQL that was being prepared, would then look something like this:</p>
<blockquote><p>&#8216;SELECT id FROM folks WHERE first_name LIKE &#8216;Jo?hnny&#8217;</p></blockquote>
<p>The question marks would be interpreted by PDO as variable markers, which rightfully didn&#8217;t exist.</p>
<p>So, the real solution wound up being a little bit of a mix between the client&#8217;s problem, and our own. Granted, we needed to catch question marks being stored in db before they got there. That improves the longevity of our own code. However, the search functionality will still return results that <em>may</em> have question marks in them, thus causing the same issue. That issue is resolved by using Mysqli, but that feels more like a hack, than a solution.</p>
<p>Anyways, I spent a long time trying to search the answer to this and found nothing except the one mention in the issue tracker. For those of you using Zend Lucence Search on Red Hat / CentOS servers. Make sure you use Mysql if you&#8217;re using the Zend ORM to populate models based on results returned from the index. </p>
<p>Oh yeah, and make sure you filter your input too, Mr. Bobby Tables&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://corycollier.com/2008/10/red-hat-vs-pdo-vs-pcre-vs-zend-lucene-search/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alternative PHP Cache Problems</title>
		<link>http://corycollier.com/2007/05/alternative-php-cache-problems/</link>
		<comments>http://corycollier.com/2007/05/alternative-php-cache-problems/#comments</comments>
		<pubDate>Thu, 31 May 2007 18:32:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[troubleshoot]]></category>

		<guid isPermaLink="false">http://corycollier.com/?p=28</guid>
		<description><![CDATA[Recently, Derek and I were running into problems with CGI errors on our development server for NFI Studios. We had recently upgraded our PHP install from 5.0 to 5.2, so we started looking for differences between the two. After a brief search on Google, I came up with a German forum with a potential solution: [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a href="http://derekgallo.com/">Derek</a> and I were running into problems with CGI errors on our development server for <a href="http://nfistudios.com/">NFI Studios</a>. We had recently upgraded our PHP install from 5.0 to 5.2, so we started looking for differences between the two.</p>
<p>After a brief search on Google, I came up with a German forum with a potential solution: APC (Alternative PHP Cache). It turns out that Caching for PHP 5.2 is different than for PHP 5.0. So, I turned of APC (by editing the php.ini file).</p>
<p>For all of you coders out there, just an FYI.</p>
]]></content:encoded>
			<wfw:commentRss>http://corycollier.com/2007/05/alternative-php-cache-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
