Another day, another “head first” book

With pleasure I found out that Head First Design Patterns was in the bookstore I’m usually getting tech-books at (I like going to a store, buying the book and then immediately begin reading it – this is why I don’t order all books over the web). The book was hidden in the shelf full of UML-books where it should have been placed near the Java-books: It’s really Java-centric.

As I noted here, I really like the head first series and if you ask me, head first design patterns is the best so far which may be because the topic really, really interests me. Additionally, I so far found much less mistakes than in head first jsp (where there were quite some).

This new book of the series has something the others don’t: It has suspense. Always when one of the patterns is explained, I’m so much looking forward to learn what the next pattern will be and what the next example will be.

I’m not a theoretical guy, so it’s quite difficult to keep me reading when dry topics are to be explained. Not so with head first design patterns: They keep it interesting and they keep explaining by example (very good ones by the way). It’s really well done.

I’m now about in the middle of the book (the command pattern) and while I alreay knew some things, I was able to learn a good deal of new stuff (and the correct terminlogoy to use) and interestingly, it’s sticking in my brain. I can remember every single important thing (the rocket-powered rubber-duck, for example. Btw: Rubber-ducks do fly indeed: Just throw it out of the window and they fly – in one direction only, but they do fly. The fly()-method would have had to be overriden by many ducks anyways, but I agree, the strategy-pattern is the better solution).

Even if you are not interested in design-patterns: Go and get this book. Even during reading the very first chapter you’ll soon get interested and by the middle of the book you long for every second of free time to continue going on reading just to learn what the next pattern may be and what example may be used to explain it.

Incredibly great stuff.

Just one year to go…

… and I’m on this world for a quarter of a century.

Today is my 24th birthday.

Sometime I really would like to be much older than I’m now. I would so much have liked to get the whole IT revolution – as it stands now, the first real program I wrote (besides many complicated batchfiles) was for Windows 95, so I missed all the fun of segmented memory and assembler. Too bad.

Then again: There are those days where I just whish to be younger so I will be able to see even more new technologies rise and vanish before I die. It would be so nice to be still alive when we finally get fusion reactors, warp speed, matter-transporters and all this stuff.

I love technology. I really do.

A worm named pilif?

I just heard, that my nickname-ever-since has been “misused” by someone in his evil malware-schemes.

At least the second entry in google after searching for “pilif” points to this page

This is very unfortunate. I’m using the name “pilif” since long before the first mail virus (ILOVEYOU) has been written. Pilif has the benefit of being nearly unused in the web so far (very convinient when registering somewhere) and it somewhat contains my name (Philip -> Filip -> Pilif)

I can asssure you that I have nothing to do with this worm or any other worm for that matter.

Besides, if I really wrote a virus I would never be so stupid as to name it after my nickname ;-)

Serendipity

Last sunday I somehow came across Serendipity.

Besides being the only project where hitting Ctrl-V is simpler than actually spelling the name (let alone pronouncing it), this blogging engine shows much promise for me.

It has some obvious advantages over MT for me:

  • It’s OpenSource. Hacking it isn’t a crime.
  • It’s written in PHP, one of the languages I’m really fluent in.
  • It has some great anti-spam-features (though forcing the preview here did help greatly).
  • It uses dynamically generated pages instead of statically generating each an every page.
  • It has many more features than MT does.

My only problem: It does not have an importer for Movable Type. Well, actually, the current CVS HEAD does, but it does not work either. But because of the first two points above, I could do something about that.

Now, this evening, I will be working on the comments importer and tomorrow you will be able to have a look at how well my patches work (at least with this blogs data)

And sometime later this year, I will be using Serendipity as my blogging engine (hopefully with many more patches by myself). That’s for sure!

eAccelerator

Maybe, you remember turck-mmcache, a bytcode-cache for PHP, released under the GNU GPL which was said to be extremely fast.

It’s author got employed by Zend (the maker of another bytecode-cache, but a commercial one) and turck-mmcache was lingering around unmaintained since then (about a year ago).

Then PHP5 was released and truck-mmcache stopped working.

Finally, last month, some guys forked the dead mmcache and created eAccelerator, first fixing up the cache and optimizer to work with PHP5

And today, I gave it a shot on our developement-server, just to see, if this magical cache-thing really works.

I run ab on one of the most calculating intensive pages of my current project (which makes heavy use of PHP5s new object oriented language features).

Most interesting would be the “Requests per second” value:

Without eAccelerator: Requests per second: 7.89 [#/sec] (mean)

With eAccelerator: Requests per second: 24.77 [#/sec] (mean)

Which is a factor 3 speed increase.

Please note that the absolute values are somewhat irrelevant as this server is quite a weak developement server and DB, Application and ab all run on this same machine. Anyway. The relative three-fold speed-increase is quite cool. As soon as I have more confidence in eAccelerator, I think I’m going to deploy it in the productive environement.

Btw: if your are trying this out for yourselves: Your mileage may vary somewhat. The tested application uses quite many classes all separated into different files, so this is a case where a bytecode-cache can help greatly.

What I hate about PHP

This is what I really hate about PHP:

pilif@galadriel ~ % cat test.php
<?
if (10 == '10ABC')
    echo "Gnegg!n";
?>
pilif@galadriel ~ % php test.php
Gnegg!

This is the reason for a pretty serious bug in my current i’m-loving-doing-that-as-it’s-the-greatest-ever-project

What happens is that PHP implicitly converts 10ABC to an integer (yielding 10) and then making an integer comparison.

In my oppinion, this is wrong as inplicitely converting a string to an integer can cause information to be lost. Would PHP have converted 10 to ’10’, the comparison would have worked like one expects because converting an intger to a string works without losing information.

Then again, integer-conversions are more accurate than string conversions, so I can understand PHP’s way. What I cannot understand is that a non-integer string is converted to something else than 0 or nothing (while causing a runtime-error). The comparison in my example should never have evaluated to a true value (which happened, because intval('10abc') == 10!

And converting to string if one argument of a comparison is a string is not the holy grail either – problems with locale-specific decimal points come to mind (is it . or ,?).

So perls idea of using a dedicated string comparison operator may not have been a bad idea after all…

Horde 3.0

Today Horde 3.0 along with some applications using it, the most noteworthy being IMP 4.0, has been released.

For me, horde has a long history of being a pain in the ass to install and extend. While installing the first versions has been quite easy (but not possible for me back then as I did not have access to my own server and the environement of our shared hoster did not have all the extensions needed – let alone shell access), it grew quite complicated with 3.0 onwards.

My main problem has been and is that Horde is not really a framework for application developement, but a frontend-container. It’s not possible to just install IMP. You’re always installing a kind-of groupware-application (Horde) and only them the webmail component

If you don’t do it right, you actually force your users to login in twice when checking their email (once in horde, once in IMP)

As always, I really had to take a look at those new releases.

As the horde main server is quite busy currently, I’ve downloaded from the mirror in the netherlands – the others where either not reachable or not current.

After downloading the horde framework, satisfying the very long list of dependencies took some time. Especially tricky was the fileinfo PECL-extension but this was because of a problem with my local PHP installation. Glad I found out now and could fix it

Then came the configuration. What a nicely done web interface! Unfortunately, I just managed to lock myself out (I chose “IMAP Server” as authentication source not knowing that this only works after IMP is installed and IMP cannot be installed without a working horde installation…)

After those things where setteled, I came to the installation of IMP. Easy procedure here – after getting used to with the framework itself before.

Then I’ve configured horde to use IMP as authentication source which did not work at first but after copying over the backup configuration file and trying again, it finally worked (don’t ask me what I did the second time).

My next problem was the preset settings for my users: Per default, it’s using a 12 hours time format, Arabia as location and somewhere in Africa for the time zone.

As I cannot ask my (possible) users to change those preferences, I looked for a way to do that and while doing that I began to understand how the Horde configuration system works.

Now, I’m quite impressed about how they are doing this: it’s generic, it’s configurable and every single feature can be locked down for the end users. Very nice.

Just make your configuration changes in config/prefs.php. If you need a list of possible values, either read the source, or easier: Just look at the HTML source of the preferences-screens.

If I had a whish for the next release: Provide a way for the administrator changing those settings via the Web-Frontend.

While I first just installed IMP, which worked flawslessly out-of-the box, I ventured further and installed kronolith, turba, nag and fiinally even chora. Additionally, I configured Horde to give access to chora only to me. Comfortable. Even more impressive, when I recall that the whole user-management is done via the XAMS environement (by using IMP to authenicate the users).

All in all, I still would whish to hide away horde and just install IMP (with a small, simple integrated addressbook), but as a) IMP really is the best (PHP-based – I don’t know no others) webmailer out there and as the other applications work really nicely (even with PHP5, though it’s not officially supported), I can live with that limitation.

Now, I have two tasks ahead of me:

  1. Provide support for changing the XAMS account password from within the web interface. This will be a great opportunity to learn how the preferences system really works.
  2. Teach Ingo how to create Exim-Filters as this is the filtering system that could most easily be integrated into XAMS. When I designed the initial draft of XAMS (then still called pmail), I took great pride that the mail delivery does not cause a non MTA-process to be forked an I want to keep it that way. It saves resources under high mail load.

After the christmas days, I certainly will know what the new Horde/IMP is made of. From an Administrators/Users perspective, it’s a great release.

Thank you guys!

Apache 2

There was this discussion recently about whether Apache 2.0 should be recommended by the PHP guys or not.

While I find their warning a bit too harsh, I for myself still cannot run Apache 2 – though I’d really like to. So maybe it’s time to add my two cents:

Last march, I was going to newly set up our productive server. As the apache guys keep telling that Apache 2.0 is production ready, I first went with the new version of course. Here’s what did not work and finally forced me to go back to 1.3: It’s not about PHP at all: The two extensions I’m depending on (MySQL and PostgreSQL) are available in a threadsafe edition, so even one of the threaded MPMs would have worked. What killed my intentions was mod_perl.

Back then, when the comment-spam problem was not that a big one for me, I have been running gnegg.ch in a mod_perl environement which at that time was not setupable with Apache 2: mod_perl itself had an even bigger warning about not working well than PHP still has. And additionally, they’ve changed their API, so even if I’d been able to get it to work, there would have been no guarantees of getting MT to work with that new api.

Anyway: I’ve been willing to try it out, but libapreq, required by MT when running in mod_perl, was only available as an early preview too (still isn’t nowhere near production ready). My tries in installing it anyway lead to a flurry of SIGSEGVs in Apache when using MT. Judging from the Gentoo bugtracker this has not gotten better yet.

One of the strongest selling-points for Apache isn’t PHP. It’s mod_perl. And currently, it’s mod_perl that should have this big warning on its webpage. Mod_perl and not PHP (which works nicely under Apache 2 in an internal developement system).

And even when mod_perl gets fixed: As they have changed the API, many existing (and not longer maintained) packages using mod_perl (like Apache::MP3 for example) will possibly stop working after the switch to Apache 2.

As soon as the first guy comes here and posts that he/she’s gotten MT to work under mod_perl on Apache 2, I’m going to reconsider the switch. Not a second earlier.

Wasted hours

Today I wasted three hours finding a bug in my code: A server-side plugin of our PopScan-Server recently stopped working. Looking at the code, I’ve quickly seen that some queries to the customers MS SQL-Server seemed to fail.

Nothing helped. I did not even get a message what’s going wrong. mssql_query() just returned false.

In the end, I created a small, reproducible testcase and reported a bug in PHP. And guess what: It’s already fixed.

This seems to have been introduced between 5.0.2 and 5.0.3 which is bad as I had to update because of the recent security problems. I really find it questionable that a security-update can introduce non-related bugs. But that’s live. I’m happy for now.

This is the first time in the last 6 years I’ve been working with PHP so far that I’ve been hit by a bug in PHP itself in a critical situation. This also is the reason why I wasted three hours searching for the bug in my code instead of going after PHP. I just thrusted PHP more than myself.