Complete PHP refactor.

Because Alex Toumey can't code.