Profiling PHP with Xdebug and KCacheGrind

Profiling can provide real revelations.

Sometimes, you have that gut feeling that a certain code path is the performance bottleneck. Then you go ahead and fix that only to see, that the code is still slow.

This is when a profiler kicks in: It helps you determine the real bottlenecks, so you can start fixing them

The PHP IDE I’m currently using, Zend Studio (it’s the only PHP IDE filling my requirements on the Mac currently) does have a built-in profiler, but it’s a real bitch to set up.

You need to install some binary component into your web server. Then the IDE should be able to debug and profile your application.

Emphasis on “should”.

I got it to work once, but it broke soon after and I never really felt inclined to put more effort into this – even more so as I’m from time to time working with a snapshot version of PHP for which the provided binary component may not work at all.

There’s an open source solution that works much better both in terms of information you can get out of it and in terms of ease of setup and use.

It’s Xdebug.

On gentoo, installing is a matter of emerge dev-php5/xdebug and on other systems, pear install xdebug might do the trick.

Configuration is easy too.

Xdebug generates profiling information in the same format as valgrind, the incredible debugger the KDE people created.

And once you have that profiling information, you can use a tool like KCacheGrind to evaluate the data you’ve collected.

The tool provides some incredibly useful views of your code, making finding performance problems a joyful experience.

Best of all though is that I was able to compile KCacheGrind along with its dependencies on my MacBook Pro – another big advantage of having a real UNIX backend on your desktop.

By the way: Xdebug also is a debugger for PHP, though I’ve never used it for that as I never felt the need to step through PHP code. Because you don’t have to compile it, you are often faster by instrumenting the code and just running the thing – especially once the code is spreading over a multitude of files.

Backup with dirvish

Using tape drives for your backups (in contrast to for example external hard drives) has some advantages and a whole lot of disadvantages which makes it impractical for me and a whole lot of other people:

  • There’s (next to) no random access. Need a specific file? Often you have to restore the backup until that file is restored.
  • Tapes are maintenance intensive: You have to clean the streamer, clean the tapes, store the tapes in specific environmental conditions and so on.
  • Tapes are a slow medium. You won’t get much more than 5-10 MB/s while writing to the tape.
  • The inaccuracy of tapes makes a verify run something important if not absolutely needed to do.
  • The equipment is expensive. Both tapes and streamer (or tape robots) cost quite some money.

That’s why I am using external hard drives for quite some time now. Granted, they have some serious disadvantages in long-livety (but they still outperform tapes not stored in said environmental conditions), but really important documents must be archived on a read-only medium anyways.

What harddisks provide you with is cheap storage, random access and the possibility to use common file system access tools to work with them.

External drives can be disconnected and stored at a different location from the backup machine and as they have a much larger capacity per medium than tape drives, you usually get away with one or two drives where you’d use many more tapes (at least in the affordable range of things).

If you need a pragmatic yet perfectly working and clever backup solution to fill up these external drives, I’d recommend dirvish

Dirvish uses existing tools like SSH and mainly rsync to create backups.

What I like most about it is it’s functionality to create incremental backups by creating hardlinks to non-changed files (actually a feature of rsync).

That way, a initial backup of 22G can be incrementally backed up creating only 20M of more/different data here on my system I’m currently looking at.

This obviously depends on the type of data you are backing up and as the mechanism is file-based (it always operates on complete files), your savings won’t be that good if you back up ever growing files like log files.

Still. For my use, dirvish does exactly what I want it to do and it does it very, very well. Perfect!

The tool creates backup sets as folders containing all the backed up files in their original structure. Restoring a specific file this is very, very easy.

To get you started, I would recommend you reading the dirvish HOWTO by Jason Boxman – especially as dirvish uses sometimes not quite obvious terminology.

IE7 – Where is the menu?

Today, I finally went ahead and installed the current Beta 3 of Internet Explorer, so I too will have the opportunity to comment on it.

What I ask myself is: Where is the menu?

Well. I know it’s to the right of the screen behind these buttons. But it’s no real menu. It’s something menu-alike.

Why radically change the GUI? Even in Vista itself, there won’t be a menu any more. Or at least not a permanently visible one.

The problem is: It took me years to teach my parents, that all functionality of a program is accessible via the menu and that the menu is always at the top of the application (whereas it’s at the top of the screen on the mac).

Now with this new mood of removing the menus and putting them behind arbitrary buttons, how will I explain my parents how to use the application? I can’t say “Go to File / Save” any more. Besides the names of the menu items, in the future I will also have to remember where the menu is.

And as each application will do it differently, I’ll have to remember it countless of times for different applications.

And even if I know: How to explain it to them? “Click that Icon with the cogwheel”? I doubt they’d associate that icon with the same thing as I do. Thankfully in IE7, there’s still text so I could say “Click on Tools”. But what if some “intelligent” UI designer decides that not even the text is needed any more?

In my opinion, removing the menu has nothing to do with making the application easier to use. It’s all about looking different. And looking different is counter-productive to usability. Why move away from something everyone knows? Why change for changes sake?

It’s not that people were overwhelmed by that one line of text at the top of the application. People that didn’t use the menu didn’t bother. But in the case where they needed it, or needed assistance in using it, it was clear where it was and how to use it.

This has changed now.

And even worse: It has changed in a non-consistant way: Each application will display its own menu replacement where each one will work in a different way.

So I repeat my question: How can I teach my parents how to use one of these new applications? How can I remotely support them if I can’t make them “read the menu” when I’m not sure of the layout of the application in question?

Thankfully, for my parents browsing needs, all this doesn’t apply: They are happy users of Firefox.

But I’m still afraid of the day when the new layouts will come in effect in Office, Acrobat and even the file system explorer (in vista). How to help them? How to support them?

Usable Playstation emulation

Up until now, the Playstation emulation scene was – in my opinion – in a desolate state: Emulators do exist, but they are dependant on awfully complicated to configure plugins each with its own bugs and features and none of the emulators were updated in the last two years.

Up until now, the best thing you could do was to use ePSXe with the right plugins. What you got then was a working emulation with glitches all over the place. Nothing even remotely comparable to the real thing.

And it failed my personal acceptance check: Final Fantasy 7 had severe performance problems (“slideshow” after battle and before opening the menu interface) and the blurred color animation on the start of a battle didn’t work either.

Well. I was used to the latter problem: They never worked and it was – for me – a given fact that these animations just don’t work in emulators

The other thing that didn’t work in epsxe was FFIX. You could play up to that village where they are creating these black mage robots. The emulator crashed on the airship movie after that part of the game. The workaround was to downgrade to epsxe 1.5.1 which actually worked, but IMHO that just underlines the fact that epsxe is not what I’d call working software.

I was not willing to cope with that – mainly because I own a PSOne, so I could use that. Unfortunately, it’s an european machine though and both games I own and I’m currently interested in replaying, FFIX and FFVI, are german and especially FFVI is the worst translation I’ve ever seen in a game (even the manual was bad, btw).

So, there is some incentive in getting an emulator to work: You know, getting the US versions of the games isn’t exactly hard, but playing them on a european console is quite the challenge even if the games were optained through retail channels.

Keep in mind that a) both games are no longer sold and b) I own them already albeit in the wrong language.

And today I found for the Playstation what ZSNES was compared to Snes9x back in 1995: I’m talking about the emulator pSX emulator.

Granted. The name is awfully uninventive, but the software behind that name, well… works very, very nicely:

  • No cryptic plugins needed. Unpack, run, play.
  • It’s fast. No performance problems at all on my MacBook Pro (using BootCamp)
  • It’s stable. It just does not crash on me.
  • And you know what: Even the color animations work – precisely these color animations which we were told would never work properly on PC hardware.

But I’m not finished yet: The software even is under active development! And the author is actually taking and even fixing(!) bug reports. He/She is never blaming the player for bad configurations on the emulators forum. He’s always looking into reports and often fixing the stuff reported.

It’s not Free (freedom) software. It’s Windows only. But it has one hell of an advantage over all other Playstation emulators out there: It works.

As I hinted above: This is just like SNES emulation back in 1995: You had many abandoned projects, one emulator you were told was good (Snes9x) and one that worked (ZSNES). It looks like history is once again repeating itself.

My big, heartfelt thanks to whoever is behind pSX emulator! You rock!

After 13 years something new in Monkey Island

It has been 14 years ago that I played Monkey Island for the first time. Well… maybe 13. I just don’t remember exactly if it was 1992 or 1993 when my parents finally bought a computer and I illegally copied the game from a classmate (including a photocopied version of that “copy protection” wheel).

Of course it didn’t take me 13 years to complete it. But the game was so incredibly cool that I played through it over and over again. And with the downfall of DOS came the advent of ScummVM, allowing me to still play the game.

And just now I started another run – probably because I’ve seen Pirates of the Carribean 2 last monday and I noticed quite some similarities to Monkey Island – especially the second part (Voodoo Lady in a swamp comes to mind)

Anyways. Today was the first time ever I’ve seen the scene I screenshotted there.

In all my previous runs, I always “salvaged” the idol as my last task which mean that as soon as I got out of the water, I’ve seen the ghost ship fade away with Elaine on it.

Now, I did it first as it actually makes sense as that task requires the least amount of walking around, which led me to see this cute scene between Guybrush and Elaine (and not to mention her stupid excuse for not kissing shortly afterwards.

How nice to find something new after 13 long years.

mod_php, LightTPD, FastCGI – What’s fastest?

Remember last April where I found out that Ruby on Rails was that quick compared to a PHP application? Remember when I told that it may be caused by FastCGI, but that I didn’t have the time to benchmark the thing properly?

Well… today I needed to know.

This article is even larger than my usual articles, so I had to split it up and create an extended entry. I hope you don’t mind.

Continue reading “mod_php, LightTPD, FastCGI – What’s fastest?”