The PHP Hierarchy of Needs

We had a lecture about Unit Testing in our local PHP user group last week. I really like these meetings because there is usually good interaction between some very experienced developers and some very inexperienced ones.

Following the usual “but why is it better then just running it in my browser and seeing that it works” question made by one of the younglings, we got into a discussion of why Unit Testing it so good, and especially, why is it such an addictive practice and why people who do it (including myself) tend to love it so much.

And then it hit me: [more...]

GNOME doesn’t detect MIME types anymore

After a recent upgrade (Gentoo being Gentoo) my GNOME desktop stopped detecting file MIME types. All files in Nautilus whould show as plain files with no type icons, and all application associations have stopped working.

I tried re-emerging a bunch of stuff like gnome-mime-data and mime-data and nothing helped.

After lots of research, I did this (as regular user):
$ update-mime-database .local/share/mime
This actually worked! It threw out some errors regarding specific files, but it did work! I’m not sure what it does, but after restarting Nautilus (by doing the usual killall nautilus) I got my desktop properly working again.

Ahh.. got to love Gentoo - no other distro gives you these challenges and the satisfaction that comes with solving them - or as Gentoo folks say, “If it’s broken - fix it. If it ain’t broken, break it” ;)

Zend Framework Components Presentation @ DLW08

I’ve just finished my one hour talk at Dynamic Languages Europe titled “Zend Framework Components for Non-Framework Development”. Despite the long name, the presentation’s concept is quite simple: It’s an overview of some of the use-at-will, standalone components of ZF and how you can use them even in a non-ZF application.

The presentation went quite well and the room was full (and hot) - the fact that people actually stood throughout the presentation shows how popular ZF is nowdays (well, it was a small room - but still ;)

I didn’t have time to go through all the components I planned to (skipped Zend_Json and Zend_Log) but I still feel it was a good session.

You can download the slides here, or see it on Slideshare:

A small recommendation for those of you who present a lot: I used my newly-bought Logitech Cordless Presenter for the first time, and it really helped me. It doesn’t look so sexy (even for a shaver) but it has everything you need - remote control for the slides, laser pointer, timer to manage time (it will vibrate every 5 minutes if you want which I find very useful because I have hard time managing time when I present) and even a button to blank the screen. It connects through USB and is detected like any keyboard - so it worked perfectly with my Linux/OpenOffice and should work with Windows/MS Office and Mac (I suppose) as well.

Playing with CouchDB View Collations

I've been playing with CouchDB quite a lot lately. While it's still far from feature-complete, I think it's a cool project. Generally the concept of object databases is a new thing to me, growing up in the web where for most people "database" == "Relational Database".

Since CouchDB related documentation is still scarce, I decided to share a cool thing I managed to pull around today with CouchDB's view API.

For the purpose of playing with CouchDB, I decided to write a PHP-implemented CouchDB interface (yes, I know there are exiting ones) I currently dub "Sopha" and a Wiki using CouchDB and Sopha as backend (if I ever get those to a stage where they would actually work, I will probably release them as open source).

One of the design goals of my Wiki, was that previous revisions of each page are kept and can be accessed. While CouchDB keeps track of object revisions, access to old revisions is not guarantees as those eventually get deleted - So I had to implement my own revision tracking of pages. The design I went for was simple: each revision in it's own document in the DB. They all have the same "title" field - but an incrementing revision number, starting from 1 (for new pages) and going up.

This design poses one major problem: how do you easily access the single most recent revision?

I started by creating 3 different view functions for accessing wiki pages: one to access the most recent revision of a page by it's title, one to access a specific revision of a page by title and revision number, and another one - to fetch all the revisions of a specific page by it's title.

This was a mistake, and it resulted from my years of thinking relational (keys, indexes, SQL, etc.). As I worked my way through, I started understanding the power and magic of CouchDB's views and view collations. With proper collation use, it turns out it only takes one view function to rule them all:

CODE:
  1. function(doc) {
  2.   if (doc.doctype == "WikiPage") {
  3.     map([doc.title, doc.revision], doc);
  4.   }
  5. }

Using this view function, I could do the following ("titlerev" is the name of my view function, URLs are decoded for readability):

Access the specific revision 123 of a specific page titled "My Page":
GET /database/_view/wikipage/titlerev?key=["My Page", 123]

Access all the revisions of "My Page":
GET /database/_view/wikipage/titlerev?startkey=["My Page"]&endkey=["My Page", "Z"]
This will work because CouchDB orders the results according to their key - and has strictly defined ordering rules - so ["My Page"] will always come before ["My Page", 1] and ["My Page", "Z"] will always be after ["My Page", n] as long as n is a number.

Access the latest revision of "My Page":
GET /database/_view/wikipage/titlerev?startkey=["My Page", "Z"]&endkey=["My Page", 0]&decending=true&count=1
This works as well - because records are selected in reverse order from ["My Page", "Z"] to ["My Page", 0] - but only the first one is returned - so it will always be the one with highest revision number.

How cool is that?

BTW there is a good article which also explains CouchDB view collations at cmlenz's (one of the contributors to CouchDB) blog.

Security By Obscurity - “Not to Stand Up”

I am giving a security lecture at the local PHP users group tomorrow, and one of the topics is, ahm, security by obscurity. In fact, it's not really a topic - I just mention it and say that it's not really an approach to security, and should generally only be used as an extra measure and should not to be relied on.

This got me thinking about one of my old-time favorite Monty Python sketches:

The first rule of not being seen: not to stand up!

Reducing your bandwidth for benchmarking purposes

In the last few days I've been busy doing allot of web application performance benchmarks. For some of these benchmarks, it was important to simulate a real end-user's average effective bandwidth (real-world download / upload speed from the end user's perspective).

Since we used a fast, clean LAN for our benchmarks (you can't get consistent numbers otherwise), we had to find a way to somehow limit the bandwidth of our LAN so that it would resemble "real Internet" throughputs. Since it took some research and reading to find the best way to do that, I've decided to write a quick HOWTO to describe what we've done.

[more...]

PHP Israel: First meeting

Yesterday we had the first meeting of the newly founded Israeli group of PHP users, or "Kvutzat Mishtamshey PHP Beysra'el" as one might say.

The meeting was held at Zend offices, and there was a pretty good turnover - ~20 non-Zenders showed up with ~10 more Zenders joining in. I gave a presentation (slides are in Hebrew but you can get them here if you read that funny language) about the past, present and future of PHP. There was also a trivia quiz (yes, I stole some ideas from a PHP Norge meeting I attended some months back) and we gave a book and a couple of T-Shirts (and a PHP stress ball) to the winners.

Boaz took some pretty good pictures as well.

It was lots of fun and good socializing which was exactly what I hoped for. The general idea is to have a meeting once a month or so - hopefully, next time I will be sitting and asking questions and not presenting.

Thanks everyone for coming, and if you happen to be in Israel, and do PHP - you should come as well!

Canon EOS Rebel / 400D, libgphoto2 and Gentoo

I had some troubles yesterday importing images from my new Canon EOS Rebel XTi to my Gentoo - I installed UFRaw and gtKam and was trying to import RAW images into GIMP. For some reason gphoto2 wasn't seeing my camera (although it was listed with lsusb) and so I couldn't import photos from it using any application.

After several attempts (and very little information on Google), I gave up and went to sleep. Today I tried again and a solution came surprisingly fast: The problem was probably that I didn't compile libgphoto with ptp2 support. What I did was:

- Add 'CAMERA="canon ptp2"' to /etc/make.conf
- Emerge libgphoto2, gphoto2 and hal again (I'm quite sure libgphoto2 was enough).

Now everything works and I'm off to play with some RAW images with GIMP.

Zend Conference POST-Mortum

Zend/PHP Conference 2007 is over - it was lots of fun and lots of work, and I enjoyed it even more than last year's ZendCon. San Francisco was as beautiful as always, meeting colleagues from all over the world (some of whom I get to see only once a year) was fun, and of course, you get to learn from the smartest people of the PHP world, and also get drunk with them!
[more...]

Happy New Year, PHP Israel Users Group!

As some of you might know, the beginning of year 5768 of the Hebrew calendar is being celebrated in Israel these days - and for the new year, me and some friends decided to try and organize PHP-Israel - a local PHP users group in our land of milk and honey (or was itblood sweat and tears?).

So now we have php-israel.org (sorry folks, it's all in Hebrew). It's been around for less than 2 weeks and we already have ~40 or so subscribers to the mailing list - quite allot are Zenders but the majority are not, which is good. We also have some traffic - people are designing a logo and talking about a first meeting.

I've always thought there's no PHP community in Israel - now I know there isn't one because nobody tried to organize the quite numerous individual PHPers into a community. Hopefully, by next year, we will have a thriving local community of PHP users, spreading the word of the free web in Israel.

Shana Tova, PHP Israel!