initial code for PHP lib. totally untested.