corycollier.com | Web Development and System Administration

I’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 every 15 minutes to see if there’s any news I should know about.

The first thing I did, to filter input, was to setup a Google Reader 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.

This still requires me to visit Google Reader, and parse through a lot of stuff (routinely over 1000 new items) to find out what’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. 

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.

I love Florida Death Metal. I’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.

Enter Zend_Http_Client ….

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. 

One minor detail, the RSS feeds aren’t publicly available. You have to be logged in to use them. This makes sense. I imagine Google doesn’t want to be used as an aggregator of RSS feeds to be used as a proxy to other sites. Sorry :/

So, here’s a breakdown of what I needed to write a script to do:

  1. Login to Google
  2. Grab the RSS Feed for ‘All Items’
  3. Parse the RSS Feed for keywords relevant to Florida Death Metal
  4. Email me alerts (if there are matches)

Not too bad. So, Here’s the script I came up with. I hope you like it :

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

Wrapping all of this up, I stuck this script on a spare debian 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.

Wrapping all of this up, I stuck this script on a spare debian 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.

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. :D

Recently while working at my new job at Hydra Studio, my buddy Rob and I came across an issue that was killing us: 

“Invalid parameter number: no parameters were bound”

 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’s server. Nothing like saying a project is solid, only to find out there’s something ’special’ about the production environment.

The first thing we did, was to list out what was unique about the client’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 ‘LAMP’ stuff pretty much matched verbatim. 

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:

PCRE

The version that’s supported on Red Hat / CentOS is 6.6. That’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.

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 …

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? 

After hours of searching for an answer on the googlez, I came across some help on the Zend Issue Tracker. 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.

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.

The SQL that was being prepared, would then look something like this:

‘SELECT id FROM folks WHERE first_name LIKE ‘Jo?hnny’

The question marks would be interpreted by PDO as variable markers, which rightfully didn’t exist.

So, the real solution wound up being a little bit of a mix between the client’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 may 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.

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’re using the Zend ORM to populate models based on results returned from the index. 

Oh yeah, and make sure you filter your input too, Mr. Bobby Tables…..

So I got a call from a client today regarding a few issues they were having. Most of the problems weren’t all that difficult to solve, save one….

The boss’s computer would immediately log off after he tried to logon. While this might sound funny (in other circumstances, it really is), the client (who is a really cool guy, whom I respect a lot) did not think it was funny at all.

So, I dived into the Google to find out the issue. The short version; there was a bad registry setting. Basically, when this sort of thing happens, the first thing you should check is the registry. Now, you can’t connect to the registry locally, since you can’t logon to the computer with this issue.

So, the first thing you need to do, is logon to a computer on the same network as a user who has administrative rights on the computer concerned. Once you’ve gotten that far, you’ll need to open regedit. Something like this:

After that, you’ll need to connect to the computer in question. That’s easy, check the following pics:

then… 

The following key is what you should be looking for:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

That key should contain a string value for ‘Userinit’. If you’re confused, you should see something like the following:

Well, you probably shouldn’t see the green box, but you should see the string value for Userinit. If you don’t see that value in the root of key Winlogon, then you’ll need to create it. 

That’s not too bad either. First, right click the right hand pane of the registry editor:

Select the ‘String Value’ item in the right click menu. Once you’ve gotten that done, you’ll have a new string value in the right hand pane, awaiting you to name it. It’ll look something like: 

Name the string Userinit. After you’ve done that, right click the entry and select ‘Modify’. Make sure that the value for the key is:

c:\windows\system32\userinit.exe

Again, here’s a picture:

And that’s it. If you have any issues after you’ve gotten this done, I recommend an ERD disk or formatting your HD. Those are extreme options, I know. However, I don’t think you want to tool around with your computer for hours on end ( or maybe you do ).

So, as  a follow up to my rant about the lack of value in most social networks that clog the arteries of the internet these days; I thought it’d be a good idea to follow up with some thoughts on networks and programs that I do like, and why I think they’re cool.

[Networks - The places online for social media]


 

 

Twitter

1. Twitter - Probably not a surprise to most tech folks out there. For those of you who don’t know (geez), twitter offers a sort of ‘micro-blogging’ platform. It’s kinda like blogging for people who don’t have time to blog. With a max post length of 140 characters (not words), you can’t say too much. However, it’s a great way to keep up to date with your friends, or important people, like Tim O’Reilly

Pownce

1.a. Pownce - For all the same as Twitter, but a different network (with more features too). This is Kevin Rose’s (Founder of Digg) Twitter Clone. 

 

Delicious

2. Delicious - I can’t begin to say how much I like Delicious. The actual site (again, for those of you who are scratching your heads right now) is del.icio.us. The idea is to have a place online where you can store your bookmarks. That way, you never have to worry about not being able to find that one video online, when you’re at your mom’s house or something.

2.a. Magnolia. - For all the same reasons as Delicious. Magnolia is just a different interface to the same idea as Delicious. 

 

 

3. Flickr - Hands down, nobody has online photo sharing down like Flickr. The amount of things you can do to your photos with Flickr is nothing short of obscene. To top it off, the developers are a pretty eclectic group of characters. Call me an idealist, but I like the idea of nutty dudes (and dudettes) writing software that really does something for the world.

[Software - The stuff on your computer that helps _you_ out]


 

 

1. Twhirl - I use Twhirl pretty much exclusively for ‘tweeting’ these days. Twhirl runs off of Adobe AIR, a sort of intermediary between a program, and it’s operating system. This means that if you’re running Windows (XP, or whatever Vista variant), Linux (within reason), or OSX; you will be running the same program. That makes for easy support. Anyways, Twhirl is awesome because it doesn’t always give me the ‘too many requests’ errors of twitteriffic, AND it posts to Pownce for me too.

 

2. Flock - Flock is a browser that’s built on top of Firefox. It makes keeping up with Social Media sites pretty easy. Some of the features of flock (like the top media bar, displaying photos and videos) are equally awesome, and cumbersome. Despite some of it’s shortcomings, Flock is still a really cool app that does a good job of combining a web browser with a social media dashboard.

 

3. Adium - Now, some of you might not think of instant messaging as a type of social network. No websites, no pictures, no birthdays, no etc… However, IM was really the first type of social network, and it was well beyond it’s time. These days, if you’re not on IM, you don’t talk much to me. Seriously, my wife has to get on IM to chat with me, when we’re in the house together. IM is king, and Adium makes using IM a breeze.

I recently read an article, referred to me from Digg, about ‘Why Macs Still Arent Right For Business‘, as written by Jonathan Blum. Being a Mac Convert, I feel a certain ownership of this issue. I see people argue over this sort of thing all of the time. There are some key arguments in favor of PCs, but not many.

This guy had some intial transition issues, and turned it into an excuse to write about the ‘flaws’ of switching to Mac. His company uses lame software that was specifically designed for windows, and complains about Mac not working for it. It’s a weird argument, ’cause he prefixes all of this by saying he’s been a Mac user for years. The issues he complains about are largely encountered by newbs. Either he’s a liar, or he’s playing ‘Devils Advocate’ for the inevitable issues new Mac converts will face.

While it is mega-lame, it does give some validity to his argument. Many small business ARE using terrible software, and would be faced with serious costs if they chose to change software and hardware at the same time. Remember, most business users don’t like computers. They’re a tool for doing a job they don’t want to do.

So the issue here really is, ‘Do you like your job’? because if you do, then you would want to use the best possible equipment to get it done. You would want to be as efficient at your job as you possibly could. If your job sucks however, then you probably just want to get it done and get out.

That’s sort of the “State Of Business” for much of corporate America. There’s a reason why everyone you meet loves ‘Office-Space’. It’s because most people have shitty jobs. It might seem like a stretch, but I think there’s a real correlation between Mac / PC users and folks with good / bad jobs.

Figure it like this: if your employer doesn’t want to fork an extra thousand bucks on a computer that works more efficiently for you, do you think they’re gonna provide any other incentives?

Doubt it.

Often, I get asked by folks why an e-mail didn’t reach someone. People get an email that has some cryptic message about why their email didn’t reach it’s intended recipient. While there are an untold number of reasons as to why that could happen, there are a few things you can do to narrow down why it failed.

Regardless, the first thing I always do, is check that the email address is valid. It might sound funny, but just like that hot girl might have given you a phony number, you might have the wrong email address. This happens a lot more often then you might think.

So, how do you check the email? Enter Telnet to the rescue. Don’t worry, Telnet is cross platform. If you have Linux, Mac, or Windows (geez), you can use Telnet to figure out if the e-mail address you’re trying to reach is valid. It’s one of the few things that seem to work on damn near any operating system you can think of.

Read the rest of this entry »

Loading the background image. This will cache after the first load.