FloFaber.com

MphpD - A PHP library for MPD

A couple days weeks ago I released version 1.0.0 of MphpD - a PHP library which let's you control the Music Player Daemon in a simple way while still supporting the whole MPD protocol.

Check out the projects website mphpd.org for details and please report any bugs on GitHub. Thanks.

How it came to be

Back in the first months of my IT career about 8 years ago my colleague told me to get myself a raspberry pi - a mini computer for fun little projects as it turned out. Not knowing what to do with it and without any knowledge of Linux whatsoever I went to YouTube and looked for things to do with it. As it turns out you can make it play music which one could control via a small webinterface using Apache and PHP. So I built one myself. It only had 4 buttons (next, previous, pause and play) and consisted of shell_exec("mpc ...") and a handwritten playlist file. Unfortunately there are no screenshots of it.

As the months went by my colleagues got themself a pair of small speakers so they can play music in the office. First they were connected to a workstation, then a Raspi running Kodi in combination with the "Play to Kodi"-Browserextension to play Music via YouTube. It worked at least most of the time but it often had hickups.

So there I was with a raspi and the knowledge of how to make it play music via a webinterface. Of course I began to write a more sophisticated version of my old '4-button mpd controller' which quickly became an abonimation of PHP code consisting of exactly 38(!) shell_execs, a bit of proc_open and some execs here and there which was not only amaturish but also absolutely insecure as there was not much escaping going on. I wonder how many remote code execution vulnerabilities there are. At least the code never saw the wides of the internet.

But it worked and did what it should. It could also play Videos from YouTube by downloading them via youtube-dl which took forever on that poor raspberry pi. Most of the time we were listening to internet radio stations. However there was also a MySQL database in the background which was then synced to MPDs playlist-files and such. Again, an abonimation. Most of the frontend was written in JavaScript/jQuery for that SPA-feeling. Unfortunately there is no screenshot of it either but I still have the source code so I will set this thing up a last time in the near future to post a screenshot here.

I pushed out one last big update and after some more time left the company. Apparently it was still running a year later. I wonder if that raspi is still alive.

A year ago me and my colleague struggled with the same issue: We had a pair of speakers and nothing to control them in a good way. Initially I looked for an existing PHP library for MPD and did not manage to find a good one. Stuff that has not been worked on for years or this thing which's documentation is non existant and it's README is written in broken english. Great. In addition I'm suffering from Not invented here-syndrome so of course I cobbled together a small TCP-client and parser + WebUI to control MPD. What else should I have done? That thing then grew into MphpD - a PHP library with good documentation. I'm currently rebuilding the WebUI in my spare time so it will be released as well somewhere in the future.