Friday 31 July 2009

Does my PHP app run on Project Zero?

As the PHP implementation in Project Zero gets more complete it's possible to run quite a few significant applications. It would be nice to know in advance how likely it is that a PHP application would run on Project Zero - without investing a whole lot of time in trying to run it. Well, now you can.

There is a new Project Zero application which will scan your application and tell you whether it thinks it will run on Project Zero. The way it does this is to extract information from the Project Zero PHP parser - for instance it finds out the names of functions that are declared in the application and compares them with the names of functions that are invoked. If the application scanner finds that a function is invoked by the application but is not declared by it, it uses function_exists() to figure out if it is implemented in Project Zero's PHP. Similar analysis is carried out for classes and methods in the application.

The instructions for extracting and running the scanner are here. They assume that you already have a working version of Project Zero.

One of the reasons that I wrote this was that I wanted to figure out if PHPUnit would run on Project Zero. This led to a horrible chicken and egg situation in that I can't write PHP without PHPUnit and most of the scanner is written in PHP. In the end I had to inch forward on both tasks simultaneously, with the final benefit that I worked out how to use PHPUnit at the same time as writing the scanner. The instructions for running PHPUnit are here. I'm not claiming full support for PHPUnit in Project Zero - but there is enough to be able to test PHP classes as you write them.

The application scanner can't say definitely whether an application will run or not, this is because it is using static analysis. However it gives enough information to be able to tell whether it's worth trying or whether you should mail the Project Zero team with your scan results and ask them when they think they will have support for your app :-)

Wednesday 8 July 2009

On no! Not more tests!

One of the problems with the incredible level of success of the PHP TestFest is that PHP gets more tests, 887 more to be precise.

Well, isn't that the point? Yes, but it's beginning to take *forever* to run them which is a bad thing and as TestFests get bigger and better this will only get worse.

A year or so ago I started worrying about this, then I met Stefan Priebsch at IPC and made him worry about it too. Together we started a project to re-factor the code that runs tests (run-tests.php) so that it could run tests in parallel.

In May we had a prototype going, it ran most of the tests in sequence. It still doesn't have all of the capability of run-tests.php but it was enough for our PHP GSOC student (Georg Gradwohl) to start writing and integrating code that would run groups of tests in parallel.

Yesterday I ran some tests on my dual core lap top - this isn't a proper benchmark and I had all sorts of other stuff going on too...but here they are:



The chart shows the time taken to run 7700 tests with the current code (old), new code sequentially (seq) and the new code with increasing numbers of parallel tasks (para). As you can see we are able to run this sample in about half the time taken by the code that is used at the moment. There is still a long way to go with this but I'm happy to say that a couple of people have started to check out the code and try and run it. At the moment this only works on *ix, supporting Windows is on the TODO list.

With the help of the 'many hands' of the PHP community I'm quietly confident that by the time PHP gets all the tests it needs we will have something that will run them efficiently :-)