Remember how I toiled away at loading a Musicbrainz mirror into MySQL? Well, I deleted that mirror.

Running queries on a database as large as Musicbrainz was remarkably sluggish with PHP, and joins were practically impossible.

Musicbrainz does offer an XML web service. So it wasn’t a terrible leap to write a simple class in PHP to query the service and parse the results.

I didn’t find much PHP development out there for Musicbrainz — Last.fm is probably the most visible Musicbrainz user developing in PHP — so I had to start from scratch. Want to see the source? Of course you do.

Note: I use the Snoopy class to connect to the web service, and the XMLParser class to parse the results. I couldn’t get the SimpleXML library to work with my Windows installation of PHP (my development environment), so I went with a library that mimicked SimpleXML.

To query Musicbrainz for a list of artists matching a particular name:

$mbSearch = new Musicbrainz_WebService;

$mbSearch->QueryArtist("Number Girl");

$artistList = $mbSearch->results->{'artist-list'}[0]->artist;

If you know the GID of an artist, you can also query for the artist’s releases:

$mbSearch = new Musicbrainz_WebService;

$mbSearch->GetArtistById("808fe413-ff00-4a68-99fe-0ab265a7e2be", "sa-Official release-rels");

And you can limit the number of results:

$mbSearch = new Musicbrainz_WebService;

$mbSearch->GetArtistById("808fe413-ff00-4a68-99fe-0ab265a7e2be", "sa-Official release-rels", 100);

You can also query by release or track and their respective IDs:

$mbSearch = new Musicbrainz_WebService;

$mbSearch->GetReleaseById("92348049-331a-480c-921b-61e420b98d2d", "release-events");

The web service does not offer all the relationships in the Musicbrainz database — no Amazon ASINs, no freedb indeces — but it is a quick and easy way to leverage the power of Musicbrainz. I use the web service to retrieve track information for Musicwhore.org. The Japanese track listing for this release is provided by Musicbrainz.

At some point, I’ll have to write some more thorough documentation, and I need to investigate ways to cache requests to the service. For now, I’ll let Musicbrainz power part of my content.