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 :)