Archive for January, 2005

I Hate Comment Spam

I have finally given up the fight against comment spam. I cannot figure out how to spam-proof Bloxsom comments, so I’ve been forced to disable them.

This means I’ll be migrating shortly to a new blog system, as comments are on my “must have” list of blog requirements.

I’ve started checking out WordPress and s9y. Hopefully, one of them will make the cut, as, all things being equal, I’d prefer to use a PHP tool. Actually, make that a PHP 5 tool.

Of course, blosxom is written in Perl, so that’s not a requirement. All I really want is something simple and easy to maintain, because I want to spend time writing blog entries, not hacking on a blog system.

I guess TypePad is always a choice, but I would prefer to run it under the trachtenberg.com domain.

In the meantime, if you want to comment about a blog entry, or anything at all, feel free to e-mail me at adam@trachtenberg.com. Sending regular, normal, plain-text e-mail is the best way to get through my spam filters and not automatically routed to /dev/null. Sorry, but 51,301 is a lot of junk.

Popularity: 6% [?]

Programming eBay Web Services with PHP 5 and Services_Ebay

My latest article is now available on the O’Reilly Network. "Programming eBay Web Services with PHP 5 and Services_Ebay" provides an introduction to eBay Web services and Stephan Schmidt’s awesome PEAR package, Services_Ebay.

As I’ve blogged before, Services_Ebay is a PHP 5-only module that makes it drop dead simple to interact with eBay Web services. This piece walks you through getting started with Services_Ebay, shows you how to search the eBay listing database, and then displays the found items in a variety of ways.

As a extra special bonus, I highlight all the cool behind-the-scenes PHP 5 magic that’s taking place. I also do some nifty stuff by overriding Stephan’s model classes to provide an alternative data view. I’m sure this will lead to nasty comments from the peanut gallery about my lack of respect for MVC.

Popularity: 9% [?]

Using the Google AdWords API with ext/soap

On Friday, Jeffrey showed me Nelson’s new Google AdWords API service. Google has now exposed all parts of the AdWords program via a SOAP Web service API.

Unfortunately, SOAP and PHP still aren’t the best of friends. True, Nelson has graciously provided us with some NuSOAP PHP example code. However, when I viewed it, I immediately barfed all over myself. Gross!

Any SOAP library that requires you to use angle-brackets is missing the point of SOAP. To be fair, I’d never used NuSOAP before today, so maybe it’s possible to rewrite the code to be more elegant, but I couldn’t stomach trying.

I mean, come on. This is no way to set a SOAP header:

// Set up the authentication headers
$email = "<email>youremail@your company.com</email>";
$password = "<password>yourpassword</password>";
$userAgent = "<useragent>YOURCOMPANY -- PHP KeywordReport Demo</useragent>";
$token = "<token>developer_token_here_</token>";
$header = $email . $password . $userAgent . $token;

And comments like this?

// With nusoap, you need to include XML with the parameters
$keyword0 = "<text>flowers</text>";
$keyword1 = "<text>chocolates</text>";
$otherinfo = "<maxCpc>50000</maxCpc><type>Broad</type>";

I need to include XML?!? Forget it.

So, out of the spirit of being a good citizen, I rewrote the "Estimating traffic for a keyword" example using PHP 5’s ext/soap extension.

// Connect to the WSDL for the TrafficEstimatorService
$wsdl = "https://adwords.google.com/api/adwords/v2/TrafficEstimatorService?wsdl";
$client = new SOAPClient($wsdl));

// Create the SOAP Headers for authentication
$ns = 'https://adwords.google.com/api/adwords/v2';
$email = new SOAPHeader($ns, 'email', 'adam@trachtenberg.com');
$password = new SOAPHeader($ns, 'password', 'XXX');
$useragent = new SOAPHeader($ns, 'useragent', 'Blah, blah');
$token = new SOAPHeader($ns, 'token', 'XXX');
$headers = array($email, $password, $useragent, $token);

// The Keywords we're interested in
$keywords = array(array('text' => 'php', 'maxCpc' => 100000, 'type'=> 'Broad'),
                  array('text' => 'mysql', 'maxCpc' => 250000, 'type' => 'Broad'),
                 );
try {
  // Make the request to estimate the keywords
  $response = $client->__soapCall('estimateKeywordList',  array($keywords), null, $headers);

  // If we got this far, $response contains the estimates
  $count = count($response->estimateKeywordListReturn);
  echo "<P>There are " . $count . " elements in the response array.";

  // A single  response is returned as an array of field values.
  // Multiple responses are returned as an array of arrays.
  if (! is_array($response->estimateKeywordListReturn)) {
    $response->estimateKeywordListReturn = array($response->estimateKeywordListReturn);
  }

  for ($i = 0; $i < $count; $i++) {
    // Need to get the keyword text out of $keywords array
    // because the keywordEstimate doesn't know the keyword text
    echo "<H3>" . $keywords[$i]['text'] . "</H3>";
    printResults($response->estimateKeywordListReturn[$i]);
  }
} catch (Exception $e) {
  // Barf
  print $e;
}

function printResults ($estimate) {
  echo "<blockquote>cpc " . $estimate->cpc;
  echo "<br>clicks " . $estimate->ctr * $estimate->impressions;
  echo "<br>ctr " . $estimate->ctr;
  echo "<br>impressions " . $estimate->impressions;
  echo "<br>notShown " . $estimate->notShownPerDay;
  echo "<br>position " . $estimate->avgPosition;
  echo "</blockquote>";
}

No more XML. Still a little kludgy because of the SOAP headers, but overall much nicer.

In the process, I found a bug involving SOAPHeader objects when you don’t want your data to live inside a namespace, but I managed to work around that by placing them inside the AdWords API namespace.

I was also thrown a little bit by the example, which places the keywords inside a “KeywordRequest” element, when the WSDL seems to want a “keywordRequests” element. (Note different capitalization and pluralization.) This had me running down all sorts of dead ends and blaming the WSDL parser.

Last, I’m confused why the server doesn’t return the keywords back to me. Forcing me to map the input and the output is a little kludgy.

Overall, however, this looks quite nice. I plan on playing around with it more later, and I’m sure our eBay API Affiliates are having a field day.

Popularity: 50% [?]

PHP Presentations I Would Like to Attend

Pulling an object out of your hat: Magical methods in PHP 5
Showing off all the cool things you can do with __construct(), __destruct(), __get(), __set(), __call(), __clone(), __sleep(), __wakeup() and __toString().
The “I”s Have It: Porting an application to MySQLi
A case study of moving from PHP 4’s MySQL extension to PHP 5’s MySQLI extension. Difficulties encountered; new features used; future directions.
PHP 5 XML Extension Bake Off
Walk through parsing a few different types of XML documents using PHP 5’s set of XML extensions: DOM, XSLT, SAX, SimpleXML, and XML Pull Parser. Show off the strengths and weaknesses of each extension; when one is better than others; which are faster to code with, more speed and memory efficient; etc.
PHP, JavaScript, and XMLHTTPRequest
Writing cool scripts using PHP, JavaScript, and XMLHTTPRequest. :)

Popularity: 3% [?]

John Hess, 87, Journalist, Food Critic, Blogger

The New York Times just ran an obituary for John Hess. I’m not one of those bloggers who loves to blog about blogging, but I was excited to see the Times refer to and provide a URL to Hess’s blog http://www.johnlhess.blogspot.com/.

AFAIK, this is the first blog mentioned in a Times obit. If not, it’s probably the first blog belonging to the subject of the obit.

Popularity: 1% [?]

Submit Your OSCON 2005 Proposals Today

The call for papers for one of my favorite conferences, the O’Reilly Open Source Convention, is open. I love OSCON because it gathers together a wide ranging set of people. I get to meet and talk to Perl guys, Python folks, and we all get to make fun of the Java dudes.

This year, I’m part of the conference committee for the PHP track. As such, I’m quite interested in putting together an interesting and wide ranging (read: kick ass) PHP track. So, if you’ve got something interesting to share with others, please submit it.

Lots of people think they need to be Rasmus (or Rasmus-like) to get their proposal accepted. This is false! If you submit a good talk, I will do my best to make sure you’re in the conference.

A good talk should have elements of least some the following:

  • Well-focused
  • Innovative
  • Intriguing
  • Practical

As a hint, right now, pretty much anything on PHP 5 is going to count as "Innovative". If you want to give a case study about migrating your site from PHP 4 to PHP 5, that would be one good idea. Other good topics are any of the new features: mysqli, sqlite, iterators, soap, etc.

I’m also interested in unit testing, non-web based PHP applications, anything web services, design patterns, PHP and JavaScript’s XMLHTTPRequest object, cool PEAR packages, etc. It doesn’t have to be PHP-centric, but something implemented in PHP or useful to PHP developers.

I’m not interested in your own custom database abstraction layer. There are too many out there already. I’m also not interested in Yet-Another-CMS, but if you were to do a bake-off and tell me which 3 PHP CMSes are the best, why, and when I should use them, that would be good.

As my final plug, OSCON is again in Portland, Oregon. This is a great town for a conference. It’s pretty, a nice walking town, the best beer town in the US, and there’s lots of fun things to do.

Popularity: 4% [?]

When You Look Up “Technical Evangelist” in the Dictionary…

You see my picture! Well, it’s actually my name. An online German/English dictionary is trying to come up with a good translation of "Technical Evangelist" into German, and I’m the example sentence.

Special thanks to my cube neighbor Dan Theurer for translation assistance.

Popularity: 1% [?]

Andi Gutmans on Web Services at SDForum

I just found out that Andi Gutmans is going to speak at SD Forum’s Web services SIG later this month. His topic is "PHP & Web Services, The Present and the Future."

The event will take place at eBay’s North Campus, at the Silicon Valley Conference Center. That’s right near the San Jose Airport. And it’s on Tuesday, January 25th, from 6:30 to 9ish. (Directions are available from the link above.)

If you live in the Bay Area, be sure to drop by. Admission is free for SDForum members, and $15 for non-members.

Popularity: 2% [?]