Tag Archives: Yahoo!

PHP Weirdness

Beware: this post is definitely not for the feint of heart. It includes a lot of code. You have been warned.

I wrote an application some time ago for my company that looks up the longitude and latitude of an address for use in our geocoding initiative. It relied on yahoo_geo(), a function written by PHP creator Rasmus Lerdorf and the Yahoo Maps API. It was largely dependent on this function:

function yahoo_geo($location) {
	$q = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&location='
	$tmp = '/tmp/yws_geo_'.md5($q);
	request_cache($q, $tmp, 43200);
	$xml = simplexml_load_file($tmp);
	$ret['precision'] = (string)$xml->Result['precision'];
	foreach($xml->Result->children() as $key=>$val) {
		if(strlen($val)) $ret[(string)$key] = (string)$val;
	return $ret;

This function worked for over two years for us with no problems at all. Then suddenly, in the last month, it started getting spotty. I fixed things by commenting out the caching parts of the function and forcing each execution to run again. Then I got errors about the libxml_use_internal_errors() function, so I commented that out. But today, the function just flat out failed, every single time returning the same error:

Warning: file_get_contents(http://XXXXXXXXXX/XXX) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/intranet/html/fetch.php on line X

What the heck? This code is all over the web. I’ve tried a million permutations of this function, including using fopen() and ob_get_contents(), and none have worked. And most frustratingly, I could load the URL successfully in Lynx and eLinks, so the machine could quickly and easily fetch the URL.

So I ventured into a sandbox I’ve never really played before: cURL. cURL is an interesting animal. But the interesting thing is, once I got it working, it worked faster than ever! So, without further ado, here is the new and improved yahoo_geo() function:

function yahoo_geo($location) {
	$q = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&location='.urlencode(trim($location));
	$ch = curl_init($q);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	$stream = ob_get_contents();
	if($stream) {
		$xml = simplexml_load_string($stream);
		$ret['precision'] = (string)$xml->Result['precision'];
		if($xml) {
			foreach($xml->Result->children() as $key=>$val) {
				if(strlen($val)) $ret[(string)$key] =  (string)$val;
		return $ret;
	} else {
		return FALSE;

Note: If you’re reproducing these functions elsewhere, be careful – WordPress may have converted the quotes into smart quotes that will need to be fixed before this script will run properly.

Tagged , , , ,

My SEO is working!

Some time ago, I decided to learn a little bit about Google Pagerank. I wanted to improve my site’s rankings in Google’s search results. I learned about Google-dancing and many of the sports that involve optimizing your page in search results. So I took the advice and redid a lot of my page to work with what I knew. Those of you that actually follow my blog have seen changes: tags, topics, changes to my XML feeds, new prettier URLs, etc. I keep track of all referers when someone hits my blog. I see Yahoo! Slurp and the Googlebot crawl me everyday. But then I started noticing something. I started seeing really simple Google searches refering to me. As of this writing, by typing:

picasaweb iphoto

into Google, firsttube.com returns as the FIRST result. In fact, if you just search for “picasaweb,” I’m the fifth result, ranked only behind Google itself, ZDNet, and Miguel de Icaza. I have a ton of traffic coming to my Picasaweb vs. Flickr article, and lots of traffic goes to my “I want Picasa on Mac” article, even though it’s mostly worthless other than me pining away.

Anyway, I definitely want to make the same types of changes on OSNews, because clearly we could always use a boost in search engine results. As a direct result of the boost firsttube.com has seen, I think I’ll be adding friendly URLs to OSNews in the next few days.

Tagged , , , ,

Review: Picasaweb vs. Flickr

Now that I’ve successfully used most of the features on both flickr.com and Picasaweb, I decided I would write a short review of the two services. The need for online photo storage is certainly a very real one, and different services have different objectives. Here’s a short breakdown.

Read more for the review.
Continue reading

Tagged , , , , , ,

Picasaweb goes Gold …well, for me at least

I’ve gone ahead and transitioned my photos from flickr to PicasaWeb. Picasaweb is simply so much easier to navigate. Yes, it’s true, there’s no easy way to include a photo in multiple albums. Yes, this is completely anti-tag-based-systems and therefore contrary to everything I preach about Gmail, but the fact is that many people simply don’t “get it” when it comes to Flickr, and I find myself frequently trying to explain to less technological relatives show to use it. I love it, but it’s simply too complex for the Average Joe to follow.

Picasaweb, on the other hand, integrates freely with Picasa and iPhoto, which makes it VERY attractive, it’s cheap ($25 a year for 6GB storage), and it’s drop dead simple. So for now, I’m on Picasaweb.

Tagged , , , , , ,