March 29, 2012

A tip for using Doxygen for PHP code

In the last few days I've spent some time researching for a documentation tool for my PHP sources, and after running a couple of circles, I've ended up using Doxygen.
It had some issues though, especially referring to namespaces in the docblock comments, because the docblock syntax allows using backslashes for commands, e.g. \param instead of @param.
I really don't understand why PHP's developers decided to use backslashes as separators for namespaces, but that's a different story.
So, if you use namespaces in docblock comments, you have to escape backslashes, but I didn't want to do that in my code, so I've created an input filter for Doxygen in PHP which does that for me.
It also appends variable names to @var type declarations, so e.g.
/**
 * @var string
 */
public $name;

becomes
/**
 * @var string $name
 */
public $name;

which would be redundant in your code, but Doxygen seems to prefer this format.

I've added the filter to a Bitbucket repository, find it here:
https://bitbucket.org/tamasimrei/misc-tools/src/master/doxygen/filter.php

Licensed under the MIT License.

See the Doxygen documentation on how to use an input filter, but basically it's just adding a line like this to your Doxyfile config file:
INPUT_FILTER = /home/tom/misc-tools/doxygen/filter.php

Comments are welcome.

March 20, 2012

Find files with Windows line endings

Just a quickie with some bash magic... I wanted to eliminate mixed and windows line endings from my source files, and after some research and development I got this command line:

find . -not -name *.svn-base -exec grep -Ils $'\r$' {} \;

You must love bash and all of these amazing you-can-do-anything commands. Just takes some time to learn them, and to be able to use them without heavy googling.

March 19, 2012

The mystery of slow XML loading - solved

Last week I've spent some time installing a VMWare hosted linux server onto my Windows 7 PC in the office, mostly because our development server is under a heavy load for several things, e.g. a Jenkins CI instance.
After some experimenting with Debian stable (squeeze) and testing (wheezy), I've ended up using Ubuntu Server 10.04 LTS, long story short because of the support from VMWare, and the available 2.6.x kernel (had network issues with the 3.2.x kernel).
It worked as a charm, installing the whole thing together with Apache, PHP5 and the required PHP modules didn't take more than 30 minutes, the testing phpinfo() page jumped into my browser like a squirrel on red bull.

I've checked out the source of one of our projects, stoked to see how it'd work with my VM. Set up virtual host, done. Configure app, done. Let's open it in a browser. Surprise! One page load took about 2 minutes. WTF?!?
OK, let's see CPU load on the VM. None.
OK, it must be HDD load then. None.
OK -I'm not giving up- the network is slow again. No.
OK, the VM apache is waiting for the response from database server. No.
OK, then what the fudge is happening? Let's run some benchmarks. Phpinfo page is loading like in no time.
OK, so it must be something with our stuff, but what? At this point I remembered that back in the old days I had a story with configuring the Exim MTA, and it had a network wait timeout...
OK, let's see what's happening on the network. After starting up iptraf, I've noticed that there's an external IP which is connected to the VM. The IP address is pointing to a w3c.org host, let's google that. And voila! after a few minutes I've learned that the PHP DOM extension is set to load the DTD for loading and parsing XML files... Our app has a setting to disable DTD loading, but I didn't like that idea, and a comment on a PHP documentation page said that the DTD's can be stored locally. At this point - 8.30PM, still in the office, feeling like a zombie - I've asked our lead developer - who was also still in the office :) - how can I have solve this thing. He pointed me to a package called w3c-dtd-xhtml holding the DTD's. After installing it, our app was running like crazy, no waiting, I could even copy the database from the dev server, and run it locally, it's still fast enough.

Today I've installed Apache on the Windows host, and set it up to reverse proxy the VM out for the others in the office, and it runs smoothly.

How could I be that stupid to say Windows when I was asked what OS I'd like to use on my PC, when almost everything I use for development is available on linux now...
... not that I wouldn't have the same issue on a linux desktop tho :)

March 3, 2012

Fix Spotify install in Ubuntu 11.10

In the last couple of weeks, I've been using Spotify to listen to music during work, and more and more at home. Unfortunately, it seems like the developers at Spotify prefer to develop for Windows, the Windows client in the office just runs without problems, and it's regularly updated.

The "Linux Preview" version is first of all a bit tricky to install, and doesn't seem to be updated in a while.  (Plus, it's not too smart that I - living in the Netherlands - cannot change the language of the page to English, if I choose the Netherlands under the 'Land' menu, I must read the whole page in Dutch.)

So, for some songs and albums I've got an error message saying

"There is a problem with the sound decoder. Spotify can't play music"

After checking everything I could with my sound settings - I own a Logitech Cooling pad with built-in speakers for my notebook, that caused me some difficulties to install under Ubuntu, but that's another story - I've found that the spotify-client-qt package depends on the libavcodec52 (3) and libavformat52 (4) packages which seem to be missing.

With some googling, I've found (1,2) that I'm - of course - not alone with this issue, and the missing packages are from an earlier version of Ubuntu. Not that I don't trust other people posting files to download services for patching your system (I don't, and you shouldn't either), downloaded the two mentioned packages from the 'local' ubuntu repository, and a third one: libavutil50 (5) because of dependency.

Installed them in the following order - and commands:

dpkg -i libavutil50_0.6.4-0ubuntu0.11.04.1_amd64.deb
dpkg -i libavcodec52_0.6.4-0ubuntu0.11.04.1_amd64.deb
dpkg -i libavformat52_0.6.4-0ubuntu0.11.04.1_amd64.deb

... and finally I can listen to Peter Gabriel songs in Spotify!

Note that I'm using 64bit Ubuntu, so if you use 32bit, you have to download and install the *_i386.deb packages.

Thanks for the authors of the original posts!

Links:

  1. https://getsatisfaction.com/spotify/topics/ubuntu_lucid_spotify_linux_preview_local_files_problem_with_sound_decoder
  2. http://www.webupd8.org/2011/12/how-to-install-native-spotify-linux.html
  3. http://nl.archive.ubuntu.com/ubuntu/pool/main/liba/libav/libavcodec52_0.6.4-0ubuntu0.11.04.1_amd64.deb
  4. http://nl.archive.ubuntu.com/ubuntu/pool/main/liba/libav/libavformat52_0.6.4-0ubuntu0.11.04.1_amd64.deb
  5. http://nl.archive.ubuntu.com/ubuntu/pool/main/liba/libav/libavutil50_0.6.4-0ubuntu0.11.04.1_amd64.deb