RSS
 

Howto: Enable PCNTL in Ubuntu PHP installations

30 Jul

PCNTL in PHP allows for some handy advanced “trickery” using the OS process functions inherent in Linux (*nix?).  I believe some features are available in Windows, but I know for certain that pcntl_fork() is not.

Anyway, it is not enabled by default, so if you want to take advantage of the functions on your Ubuntu LAMP server, you might spend hours searching the web for that magic aptitude command.  But, as far as I can tell, it doesn’t exist.

Luckily, I stumbled across this article on the Ubuntu forums, so I’m dedicating a post here with the hopes that other will find it more easily.

Please note that you’ll probably need build-essentials and a few other source compilation basics, but as long as you have that, the following code will get you what you want.

First, in your home directory:

mkdir php
cd php
apt-get source php5
cd php5-(WHATEVER_RELEASE)/ext/pcntl
phpize
./configure
make

Then:

cp modules/pcntl.so /usr/lib/php5/WHEVER_YOUR_SO_FILES_ARE/
echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini

FYI: “make install” does not appear to put the files in the correct place.

Btw, please direct any thanks/praise to skout23 on the Ubuntu forums.

 
 

WordPress 3.0, multi-sites, and migrating only some of your posts

13 Jul

I started my original blog a little over a year ago now simply as a way to have a place to post thoughts online. As it progressed and I started to flesh out my music site, I realized that I actually have at least 3 distinct types of thoughts I want to post: music-related, general commentary on my life, hobbies, and interests, and philosophical topics.

WordPress is extremely powerful, and I quickly began using its RSS functionality to feed my music related posts to my music website, but, as it turns out, this is kind of bad from a search engine perspective. I ended up using cross-domain canonical URLs to make Google happy. Additionally, it was kind of confusing. While I don’t really have much traffic to any of my sites, I like to pretend that I do, and it just wasn’t adding up.

Then comes WordPress 3.0 which allows you to host multiple blogs (even, unofficially, on multiple domains), so it gave me the opportunity to allocate content correctly to my domains.

There are drawbacks, of course.  It’s not like you get to just make posts and decide which domain you want it on.  You still have separate sites with separate management profiles, etc., it’s just that anytime you upgrade core components (such as themes, plugins, and even WordPress itself) you don’t have to do it for every blog.

Plus, all your content is in a centralized, easily accessible place.  Perhaps in the future more fine-tuned enhancements will evolve, but for the time being all I had to do was some MySQL footwork (in moving the right posts to the right blogs, which was simple enough as I already had “Music” and “Philosphy” categories).

I have had crimulus.com reserved for some time as my “personal” site — projects I’m working on, hobby showcases, etc., but I never really fleshed it out.  My music site, jeremytharp.com, is about 5 years old now, but it relayed podcast data, music news, etc. for anyone visiting that site, but, for a search engine, it treated it as if it were hosted on my actual blog which is at coffeecuphalfmoons.com.

To summarize, I just wanted to express how pleased I am with the feature as well as inform any readers (if you exist) of the changes.

Finally, for the technological grit, if anyone else intends to do this, I had to make a modification to my coffeecuphalfmoons.com theme.

I had plenty of indexed content, so now most of those are on crimulus.com or blog.jeremytharp.com, so links from search engines would generate a 404.  I simply modified my theme’s index.php send a GET request for the $_SERVER['REQUEST_URI'] on each of the domains (crimulus.com and blog.jeremytharp.com) in the event that have_posts() returned false.  If either of those requests returns a header code other than 404, I send a 301 redirect for that.

So, a search engine refers a user to http://www.coffeecuphalfmoons.com/a/post/that/i/moved/

I check (using cURL) to see if http://www.crimulus.com/a/post/that/i/moved/ or http://blog.jeremytharp.com/a/post/that/i/moved/ returns a 200, 301, etc.  If so, then it’s probably the post that was originally referred to.

This is how you help keep pagerank value and link-juice when you’re migrating only a few posts from a blog on one domain to a blog on another.  At least, that’s how I did it.

 

Customer Review – RockAuto.com

27 May

I have a 1990 Ford F-250 pickup truck that is pretty much a beater, but it’s a damn workhorse. I love the truck, but I am always fixing things on it. ;) Pretty soon it will be a 2010 model. Anyway, recently I was hauling a load of stone, and the driver’s side rear spring hanger’s rivets broke lose and bent the hanger away from the frame. On closer inspection, the rear hangers on both side are quite rusted, and they should have been replaced years ago.

I checked around local junk yards, and most of them wanted anywhere from $40 to $60 a piece for replacement hangers, or they just didn’t have them, or only had 1 (and I’m replacing both). So, being employed in a field directly tied to the internet, I checked Google. If any of you have ever searched for car parts online, you know that RockAuto.com carries pretty much everything you can find, and their prices are very reasonable (usually the cheapest outright on Google Shopping).

Lo and behold, they have my part — more importantly, they have at least 2 — new — for $20 ea. plus $10 shipping. Mondary morning (May 24, 2010) I placed the order. When I came home from work on Tuesday, the parts had arrived.

With the recent string of crappy companies I’ve been dealing with in terms of purchasing online, RockAuto.com is the most amazing breath of fresh air ever (pardon the poetical slathering, but seriously … they are awesome.) Do not hesitate to buy from them!

 

FedEx Shipping XML API Idiosyncrasies — the saga continues (PHP & Soap envelopes)

24 May

I am doing a fairly large implementation using the exposed APIs of all 4 major shippers.  I’ve posted a few notes on USPS, and I’ve been using UPS for so long it almost seems to make perfect sense.

So, while I have to applaud FedEx for the granularity and versatility of the API they have exposed, it has caused me severe headaches due to the PHP SimpleXML issues it brings up with SOAP envelopes — particularly nested soap envelopes.

Long story short, the jist of this post is to help others deal with the responses they receive from the FedEx servers (if, like me, their pre-packaged methods do not implement tidily into your application structure).

Here is a sample response of a rate request (NOTE: this is a “Warning” response, only here for demo purposes):


   <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
    <env:Body xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <v8:RateReply xmlns:v8="http://fedex.com/ws/rate/v8">
            <v8:HighestSeverity>WARNING</v8:HighestSeverity>
            <v8:Notifications>
                <v8:Severity>WARNING</v8:Severity>
                <v8:Source>crs</v8:Source>
                <v8:Code>556</v8:Code>
                <v8:Message>There are no valid services available. </v8:Message>
                <v8:LocalizedMessage>There are no valid services available. </v8:LocalizedMessage>
            </v8:Notifications>
            <v8:TransactionDetail xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
                <v8:CustomerTransactionId>TC05_Rate_Package_Groups_POS</v8:CustomerTransactionId>
            </v8:TransactionDetail>
            <v8:Version xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
                <v8:ServiceId>crs</v8:ServiceId>
                <v8:Major>8</v8:Major>
                <v8:Intermediate>0</v8:Intermediate>
                <v8:Minor>0</v8:Minor>
            </v8:Version>
        </v8:RateReply>
    </env:Body>
</soapenv:Envelope>
    

There are lots of ways you might envision accessing that precious “RateReply” tag, but to keep it simple and avoid inferences, you get to it like this:

$xml = simplexml_load_string ($xml_from_above);
$xml->children(‘http://schemas.xmlsoap.org/soap/envelope/’)->Body->children(‘http://fedex.com/ws/rate/v8′)->RateReply;

I do suppose this is obvious enough, but believe me, the nuances that can throw it off can still cause you to inadvertently lose ridiculous amounts of time on it.

Furthermore, if you prefer to do direct PHP cURL XML calls (which you probably do given that you’re reading this), you’ll find that FedEx is not terribly interested in your type of programmer. To find a simple sample XML call, you’ll have a tough time (although I managed to find it in the WSDL downloadable ZIP). However, this is a very basic call. To add additional data (such as the exotic field that apparently no one would ever think to use — “InsuredValue”) — this field has the form (EXACTLY, stuff in brackets is what can be changed) “<InsuredValue><Currency>[currencytype]</Currency><Amount>[float]</Amount></InsuredValue>”

The “InsuredValue” node/field must go immediately before the “Weight” node in the “RequestedPackageLineItems” node. (This of course reference FedEx API v8 — things may be different in future releases.)

 

USPS Shipping XML API Testing Idiosyncrasies

20 May

If you’re a web developer and happen to develop software for use in e-commerce, chances are, somewhere along the lines you’ll need or want to integrate with the big 4 shippers’ (UPS, USPS, FedEx, DHL) APIs.  You’ll find right off the bat that they all offer rather robust APIs, so your options are sufficient.

Then you’ll get to programming and realize that the documentation is pretty crappy, but specifically I want to address the idiosyncrasies of the USPS “test” environment.  Effectively, what USPS means when they say “test” is not a test of robustness of your application, but simply whether or not your application can build a sample request (an EXACT sample request), and send it to their server.  Yeah — it’s like asking a math teacher to write the numbers 1 to 30 on a sheet of paper (in order) before he/she can get hired.

The problem is, the USPS docs don’t tell you this, nor do they show you the sample request.  So, for others who are about to embark on a few hour journey finding these details on Google (or worse, emailing USPS directly …eeek) I’m going to sum up a few facts here.

The most laborious for me so far is the one I already mentioned above.  For a rate request, the docs show you a RateV3Request, but in testing you can only use a RateV2 request (which does not support package dimensions).  Also, you must use the zip codes 10022 and 20008 for origination and zip, as well as 10 lbs. 5 oz. for the weight, and “LARGE” for the size.  Everything else (LAUGH) you have leeway with.

If you don’t use these exact values, you’ll get responses like “Please enter a valid zip code for the sender” (which of course makes you think you wrote the XML incorrectly) or “The package size must be ‘Regular’, ‘Large’, or ‘Oversize.’” (even though you have “regular” quite clearly in the request.

The advice is to get to production as soon as possible, though why USPS would design things this way is beyond me, but them’s the cards, you gotta play ‘em.

I will add more here as I find them obstaclicious enough (yeah I just made up that word).

Amendment 1:  I should add that the issues about the documentation not mentioning the “canned” requests is only applicable to the PDF documentation.  It is stated quite clearly in the HTML versions.  Go figure …

 

A few thoughts on How To Train Your Dragon

17 May

Cecily and I saw this last night as a double feature (paired with Iron Man 2) at The Family Drive In Theatre in Stephens City Virginia.  Short and simple — great movie. The plot was intriguing and somewhat surprising (not like EUREKA! but Oooooh … interesting). Had all the appropriate elements, but most importantly, it kept me interested.

Summary: a young boy growing up in a village of dragon-slaying Vikings is neither strong enough to slay a dragon, nor eager to do so. In fact, he befriends one, and eventually is able to reveal things to both the dragons and the Vikings that neither knew.

Good date film, good kids film, and good manly man film as long as you don’t tell anyone how much you love it (and I loved it!). ;)

 
 

The Family Drive-In Theatre (Stephens City, Virginia) — new ownership

17 May

Recently, The Family Drive-In Theatre in Stephens City, Virginia came under new management, and I had some thoughts about the experience that I conveyed to the new owners. Rather than write a formal review here, I’m simply posting the contents of the email:

Hi, just wanted to give feedback on the theater experience.  I'll try to keep it brief, but my wife and I watched Iron Man 2/How To Train Your Dragon.

The new ticket price is still a deal, so that is good, but what I most wanted to comment on is the "announcing" over the broadcast system.

Please, if you really want to do a message like that, record it in advance, and keep it concise.  It was some very boring rambling about the new ownership, the new website, patronizing the concession stand, and while all these points are worth knowing about, it seemed like 10 minutes.  Record it early, keep it brief and upbeat.

Also, the film cut out quite a few times in the middle.  It would have been nice if someone came over the system and explained what was going on.

Otherwise, same old theater, and I look forward to seeing more movies there.  It is also a welcome change that you are bringing new movies, although an unfortunate side effect to that is increased wait times and longer lines.

Anyway, just my two cents, thought you'd be interested.

And the reply (addended 5-18-10):

Thanks Jeremy for the feedback.

We will attempt to keep announcements short.   As for the projector cutting out, it normally doesn't do that--it was pulling the film harder than it should have been on one of the projectors and we had to adjust the film tension a few times to keep from damaging the print.

look forward to seeing you again.

Sincerely

Jim Kopp
Family Drive-In Theatre
Stephens City, VA 22655

www.thefamilydriveintheatre.com
 
 

A few thoughts on Iron Man 2 (Review)

17 May

Cecily and I went to see [wiki]Iron Man 2[/wiki] at The Family Drive In Theatre in Stephens City, Virginia (not necessarily relevant, but I thought I would mention). Actually, the film was paired with How To Train Your Dragon (film) — very good pair. Anyway, I wanted to jot a few notes/give a small review (and this should be fairly brief).

Overall it was a fair to good movie — certain it would have been just as good as the first had it actually been the first. That being said, in my opinion it went a little over the top with the cheese/tongue-in-cheek/comic book cliche. The biggest example to me is the pepper spray scene. While funny, the timing was very awkward and it really kind of cheapened the scene.

Best line of the movie? (paraphrased) “Excuse me I’m fighting off a Hammer-Roid attack.” :-D That is good stuff!

Also another major high point? [wiki]Scarlett Johansson[/wiki] in tight leather (a la Uma Thurman — The Avengers) and a very hot hairdo.

So while the movie didn’t wow me, it was actually very good, just familiar and so it didn’t excite me, but it’s certainly worth seeing, and I would definitely see it again.

And the icing of the experience was when our two-year-old son woke up at the end of the movie (when AC/DC was playing over the credits) and very sleepily headbanged and rocked out. :)

[SPOILER!]

Oh and if anyone else wondered what they found in the teaser at the end of the credits, apparently it was the [wiki]Hammer of Thor[/wiki].

 
 

Google AdSense rejection and cross-domain duplicate content experience

08 Mar

Since the rejection replies you get from Google regarding applications to their AdSense program can be quite vague and even cryptic, I thought I would share my experience. First things first, you are not going to get to talk to Google directly — you have to use the forums. (Here is my thread.)

My rejection was simply:

Hello Jeremy,

Thank you for your interest in Google AdSense. Unfortunately, after
reviewing your application, we’re unable to accept you into Google AdSense
at this time.

We did not approve your application for the reasons listed below.

Issues:

- Unacceptable site content

Looking around their restrictions, I really could not find a solution, as I couldn’t find any rule that I explicitly violated.  I posted a request for insight on the forums, and a very insightful user (wasaweb) pointed out my extensive duplicate content on http://jeremytharp.com/ and http://www.coffeecuphalfmoons.com/.  And it’s true — I use my blog’s rss to feed much of the content on my music site.

Since I want to keep the sites separate, I saw no reasonable solution, but then I discovered that recently Google began allowing cross-domain canonical URLs.  Eureka!  I simply set the canonical URLs on the pages on jeremytharp.com that fed from coffeecuphalfmoons.com to the appropriate page that fed the same content on coffeecuphalfmoons.com.  When I resubmitted the AdSense application, it was approved!

Keep in mind that there are a LOT of reasons you might get rejected from AdSense, but given that this was very simply successful, I thought I would share.

I also noticed an immediate reorganization of my site:jeremytharp.com results on Google (for the better).  I’m hoping it has some positive effects on PR on both pages as well.

 
 

WORDPRESS HOW-TO: Ignore/Hide A Category On Your Home Page

28 Feb

Sometimes you don’t want a particular category to appear on your WordPress home page.  For me, I create weekly Twitter digests, and I’d rather they not be part of the page welcome.

The process of hiding them actually took me a little bit to figure out, so I thought I’d share.  It’s rather simple, so don’t blink!  :)

Simply edit “index.php” in the wp-content/themes/<your_theme_here>/ directory.

Between the lines:

<?php if (have_posts()) : ?>

and

<?php while (have_posts()) : the post(); ?>

Insert the line:

<?php if (is_home()) { query_posts("cat=-XXX"); } ?>

Be sure to replace “XXX” with the unique numeric ID of the category you want to ignore.  To find the ID, log into your admin, navigate to your categories, and select the one you want to ignore.  The number will then appear in the URL.

NOTE: Make sure you don’t delete the “-” before the “XXX” or else you will ONLY show entries from the category.

If you update your theme, you will probably have to repeat this procedure.

If you want to hide multiple categories simply append the other categories to the string with a comma: (Example: “cat=-12,-82,-4″)

It also follows, then, that this technique can also be used to hide tags, posts, etc.